标签:code get lis lin nod section solution tin turn
160. Intersection of Two Linked Lists
分别从AB循环两次。如果第一次没循环到,第二次就会在节点相遇。
public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA == null || headB == null) return null; ListNode a = headA; ListNode b = headB; while(a != b){ a = a == null ? headB : a.next; b = b == null ? headA : b.next; } return a; } }
21. Merge Two Sorted Lists
标签:code get lis lin nod section solution tin turn
原文地址:https://www.cnblogs.com/Afei-1123/p/11918925.html