Skip to content

Commit 80c913c

Browse files
authored
Create 160-Intersection-of-Two-Linked-Lists.py
1 parent 3fb2263 commit 80c913c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
9+
l1, l2 = headA, headB
10+
while l1 != l2:
11+
l1 = l1.next if l1 else headB
12+
l2 = l2.next if l2 else headA
13+
return l1

0 commit comments

Comments
 (0)