Guest User

Untitled

a guest
Oct 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. # Definition for singly-linked list.
  2. # class ListNode(object):
  3. # def __init__(self, x):
  4. # self.val = x
  5. # self.next = None
  6.  
  7. class Solution(object):
  8. def getIntersectionNode(self, headA, headB):
  9. """
  10. :type head1, head1: ListNode
  11. :rtype: ListNode
  12. """
  13. # corner case if any list is empty
  14. if headA is None or headB is None:
  15. return None
  16.  
  17. # initialize end nodes and head nodes
  18. pA = headA
  19. pB = headB
  20.  
  21. while pA is not pB:
  22. pA = headB if pA is None else pA.next
  23. pB = headA if pB is None else pB.next
  24.  
  25. return pA
Add Comment
Please, Sign In to add comment