Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created February 14, 2018 14:13
Show Gist options
  • Save s4553711/4df04993e8191f10fee26565f83b007f to your computer and use it in GitHub Desktop.
Save s4553711/4df04993e8191f10fee26565f83b007f to your computer and use it in GitHub Desktop.
/**
* 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