Simple C++ solution


  • -1
    S

    The question can be solved easily with the following code:

    while(headA&&headB) {
        if(headA->val==headB->val) {
            return headA;
        }
        else if(headA->val<headB->val) {
            headA=headA->next;
        }
        else {
            headB=headB->next;
        }
    }
    return NULL;

  • 2
    M

    It need a prerequisites that these two lists are sorted.


  • 0
    Q

    it pass?
    if all values are same.....


Log in to reply
 

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