Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for singly-linked list.
- # class ListNode(object):
- # def __init__(self, x):
- # self.val = x
- # self.next = None
- class Solution(object):
- def getIntersectionNode(self, headA, headB):
- """
- :type head1, head1: ListNode
- :rtype: ListNode
- """
- # corner case if any list is empty
- if headA is None or headB is None:
- return None
- # initialize end nodes and head nodes
- pA = headA
- pB = headB
- while pA is not pB:
- pA = headB if pA is None else pA.next
- pB = headA if pB is None else pB.next
- return pA
Add Comment
Please, Sign In to add comment