Created
February 14, 2018 14:13
-
-
Save s4553711/4df04993e8191f10fee26565f83b007f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: | |
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { | |
ListNode *p1 = headA; | |
ListNode *p2 = headB; | |
if (p1 == NULL || p2 == NULL) return NULL; | |
while (p1 != p2) { | |
p1 = p1 ? p1->next : headB; | |
p2 = p2 ? p2->next : headA; | |
} | |
return p1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment