题目:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/comments/
代码:
/**
-
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 *pa = headA;
ListNode *pb= headB;if(pa==NULL||pb == NULL) return NULL; while(pa!= pb) { pa = pa!=NULL?pa->next:headB; pb = pb!=NULL?pb->next:headA; } return pa;
}
};