Download Intersection of Two Linked Lists.py
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): # https://leetcode.com/articles/intersection-two-linked-lists/ def getIntersectionNode(self, headA, headB): """ :type head1, head1: ListNode :rtype: ListNode """ # two points if not headA or not headB: return None a, b = headA, headB ans = None while a or b: if not a: a = headB if not b: b = headA if a == b and not ans: ans = a a, b = a.next, b.next return ans
Leetcode 160 Intersection of Two Linked Lists problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.