-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListIntersection.py
More file actions
29 lines (27 loc) · 901 Bytes
/
linkedListIntersection.py
File metadata and controls
29 lines (27 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
# curNodeA = headA
# while (curNodeA):
# curNodeB = headB
# while (curNodeB):
# if (curNodeA == curNodeB != None):
# return curNodeA
# curNodeB = curNodeB.next
# curNodeA = curNodeA.next
# return 0
_set = set()
curNodeA = headA
while (curNodeA):
_set.add(curNodeA)
curNodeA = curNodeA.next
curNodeB = headB
while (curNodeB):
if (curNodeB in _set):
return curNodeB
curNodeB = curNodeB.next
return None