Why the following code is accepted?


  • 0
    S

    /**

    • Definition for singly-linked list.
    • struct ListNode {
    • int val;
      
    • struct ListNode *next;
      
    • };
      */
      struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
      struct ListNode *pa, *pb;
      if (headA == NULL || headB == NULL)
      return NULL;
      pa = headA;
      pb = headB;
      while (pa != NULL && pb != NULL) {
      if (pa->val == pb->val)
      return pa;
      else if (pa->val < pb->val)
      pa = pa->next;
      else
      pb = pb->next;
      }
      return NULL;
      }

  • 0
    S

    please select the code and click '{ }' (code) button just above the editor so that it becomes readable and some one will reply


Log in to reply
 

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