Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6a8e3fa

Browse files
authored
Create Intersection of Two Linked Lists.py
1 parent 1855074 commit 6a8e3fa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Solution - 1: O(N) Space using a Set
2+
3+
# Solution - 2: O(1) Space
4+
class Solution:
5+
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
6+
p1,p2 = headA, headB
7+
while p1 != p2:
8+
if p1:
9+
p1 = p1.next
10+
else:
11+
p1 = headB
12+
if p2:
13+
p2 = p2.next
14+
else:
15+
p2 = headA
16+
17+
return p1

0 commit comments

Comments
 (0)