python记录
两个链表的第一个公共结点
class Solution:
def FindFirstCommonNode(self, pHead1, pHead2):
# write code here
p1 = pHead1
p2 = pHead2
stack1 = []
stack2 = []
while p1:
stack1.append(p1)
p1 = p1.next
while p2:
stack2.append(p2)
p2 = p2.next
cur = None
while stack1 and stack2 and stack1[-1]==stack2[-1]:
cur = stack1.pop(-1)
stack2.pop(-1)
return cur