题目
思路
class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
/*
文艺版解释:听闻远方有你,动身跋涉千里,我吹过你吹过的风,这算不算相拥?我走过你走过的路,这算不算相逢?
走到尽头见不到你,于是走过你来时的路,等到相遇时才发现,你也走过我来时的路
浪漫的算法
2021/3/17
11:59
*/
class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
while (headA == null || headB == null) return null;
ListNode pa = headA;
ListNode pb = headB;
while (pa != pb) {
pa = pa == null ? headB : pa.next;
pb = pb == null ? headA : pb.next;
}
return pa;
}
}
思考