-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path160.cpp
36 lines (36 loc) · 798 Bytes
/
160.cpp
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
29
30
31
32
33
34
35
36
class Solution{
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB){
ListNode * st1=headA;
ListNode * st2=headB;
ListNode * st11=headA;
ListNode * st22=headB;
int len1=0;
int len2=0;
while(st11!=NULL){
st11=st11->next;
len1++;
}
while(st22!=NULL){
st22=st22->next;
len2++;
}
if(len1>len2){
int x=len1-len2;
while(x--){
st1=st1->next;
}
}
else{
int y=len2-len1;
while(y--){
st2=st2->next;
}
}
while(st1!=st2){
st1=st1->next;
st2=st2->next;
}
return st1;
}
};