-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeetCode-160.cpp
40 lines (38 loc) · 1001 Bytes
/
LeetCode-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
37
38
39
40
/*************************************************************************
> File Name: LeetCode-160.cpp
> Author:
> Mail:
> Created Time: 2020年02月26日 星期三 15时50分37秒
************************************************************************/
#include<iostream>
using namespace std;
/**
* 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==NULL||headB==NULL)return NULL;
struct ListNode *pa=headA;
struct ListNode *pb=headB;
while(pa!=pb){
pa=pa->next;
pb=pb->next;
if(pa==NULL&&pb==NULL){
return NULL;
}
if(pa==NULL){
pa=headB;
}
if(pb==NULL){
pb=headA;
}
}
return pa;
}
};