力扣https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/
// //时间复杂度m+n
// //空间复杂度1
// public class Solution {
// public ListNode GetIntersectionNode(ListNode headA, ListNode headB) {
// if(headA==null||headB==null) return null;
// ListNode curA=headA;
// ListNode curB=headB;
// int lenA=0;
// int lenB=0;
// while(curA!=null){
// lenA++;
// curA=curA.next;
// }
// while(curB!=null){
// lenB++;
// curB=curB.next;
// }
// curA=headA;
// curB=headB;
// if(lenA0){
// curA=curA.next;
// }
// while(curA!=null&&curB!=null){
// if(curA==curB){
// return curA;
// }
// curA=curA.next;
// curB=curB.next;
// }
// return null;
// }
// }
//时间复杂度m+n
//空间复杂度1
public class Solution {
public ListNode GetIntersectionNode(ListNode headA, ListNode headB) {
ListNode curA=headA;
ListNode curB=headB;
while(curA!=curB){
curA=((curA!=null)?curA.next:headB);
curB=((curB!=null)?curB.next:headA);
}
return curA;
}
}



