-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path160.cpp
More file actions
28 lines (28 loc) · 676 Bytes
/
160.cpp
File metadata and controls
28 lines (28 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 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) {
if(!headA || !headB)
return NULL;
ListNode* curr1 = headA;
ListNode* curr2 = headB;
while(curr1!=curr2){
curr1 = curr1->next;
curr2 = curr2->next;
if(curr1==curr2)
return curr1;
if(!curr1)
curr1 = headB;
if(!curr2)
curr2 = headA;
}
return curr1;
}
};