Skip to content

Commit

Permalink
Intersection of Two Linked Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 12, 2018
1 parent 5262359 commit 2dc24aa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lc160.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
"""
if headA is None or headB is None:
return None
pa = headA
pb = headB
while pa != pb:
pa = pa.next if pa else headB
pb = pb.next if pb else headA
return pa

0 comments on commit 2dc24aa

Please sign in to comment.