The Simplest C++ 8 lines solution 48ms


  • -7
    J
    class Solution {
    public:
        ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
            
            while (headA && headB) {
                if (headA->val < headB->val)
                    headA = headA->next;
                else if (headA->val > headB->val)
                    headB = headB->next;
                else if (headA->val == headB->val)
                    return headA;
            }
            return nullptr;
        }
    };

  • 0
    T

    same val not indicate same node


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.