



class Solution:
    # @param two ListNodes
    # @return the intersected ListNode
    def getIntersectionNode(self, headA, headB):
        """
        Time complexity : O(m+n)
        Space complexity : O(1)
        """
        if not headA or not headB:
            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 
7339fc6cb8c18a1f38075ce57ccc9d65f87b9d11
<mask token>

class Solution:
    <mask token>

class Solution:

    def getIntersectionNode(self, headA, headB):
        """
        Time complexity : O(m+n)
        Space complexity : O(1)
        """
        if not headA or not headB:
            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





class Solution:
    # @param two ListNodes
    # @return the intersected ListNode
    def getIntersectionNode(self, headA, headB):
        """
        Time complexity : O(m+n)
        Space complexity : O(1)
        """
        if not headA or not headB:
            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 