# 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
"""
list_dict={}
while headA:
list_dict[headA] = 1
headA = headA.next
while headB:
if headB in list_dict:
return headB
else:
headB= headB.next
Intersection of Two Linked Lists
May 29, 2017