让a+b作为链表A的新长度,b+a作为链表B的新长度。
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
ListNode* cur1=pHead1;
ListNode* cur2=pHead2;
while(cur1!=cur2){
cur1=cur1?cur1->next:pHead2;
cur2=cur2?cur2->next:pHead1;
//cur1不为NULL
// if(cur1){
// cur1=cur1->next;
// }else{
// cur1=pHead2;
// }
// if(cur2){
// cur2=cur2->next;
// }else{
// cur2=pHead1;
// }
}
return cur1;
}
};