python 剑指offer 面试题37
来源:互联网 发布:javascript var 对象 编辑:程序博客网 时间:2024/06/17 09:18
class ListNode: def __init__(self, x): self.val = x self.next = Noneclass Solution: def FindFirstCommonNode(self, pHead1, pHead2): nLength1 = self.GetListLength(pHead1) nLength2 = self.GetListLength(pHead2) nLengthDiff = abs(nLength1 - nLength2) if nLength1 > nLength2: pListHeadLong = pHead1 pListHeadShort = pHead2 else: pListHeadLong = pHead2 pListHeadShort = pHead1 for i in range(nLengthDiff): pListHeadLong = pListHeadLong.next while pListHeadLong != None and pListHeadShort != None and pListHeadLong != pListHeadShort: pListHeadLong = pListHeadLong.next pListHeadShort = pListHeadShort.next pFirstCommonNode = pListHeadLong return pFirstCommonNode def GetListLength(self, pHead): nLength = 0 while pHead != None: pHead = pHead.next nLength += 1 return nLength
阅读全文
0 0
- python 剑指offer 面试题37
- 剑指offer 面试题
- 剑指offer面试题
- 剑指Offer(面试题35~37)
- [剑指offer]python从上到下打印二叉树【面试题9.15】
- 《剑指offer》Python语言 面试题4:替换空格
- 剑指offer面试题总结
- 剑指offer面试题06
- 剑指offer面试题 04
- 剑指offer 面试题07
- 剑指offer面试题08
- 剑指offer面试题42
- 剑指offer面试题1
- 剑指offer面试题3
- 剑指offer面试题4
- 剑指offer面试题5
- 剑指offer面试题6
- 剑指offer面试题7
- 线性变换1
- python基本数据类型总结
- form表单中的input类型及其用途
- poj1149 PIGS(建图最大流)
- windows7设置定时任务运行ThinkPHP框架程序
- python 剑指offer 面试题37
- 准备数据结构项目
- SPark算子学习之FlatMap和Glom和randomSplit
- android_购物车
- ListBox实现上移,下移,左移,右移操作
- 2017/12/20
- SpringBoot中使用AOP 监控sql耗时
- 关于bin/storm nimbus >/dev/null 2>&1 &
- windows10上使用apache部署python flask webapp