题目描述
intersection-of-two-linked-lists
AC代码
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA==null||headB==null)
return null;
ListNode hA=headA,hB=headB;
while(hA!=hB){
hA=hA==null?headA:hA.next;
hB=hB==null?headB:hB.next;
}
return hA;
}
}