LeetCode 160. 相交链表

阅读 123

2022-02-07

https://leetcode-cn.com/problems/intersection-of-two-linked-lists/

 public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode list1 = headA;
        ListNode list2 = headB;
        while (list1 != list2) {
            list1 = (list1 == null) ? headB : list1.next;
            list2 = (list2 == null) ? headA : list2.next;
        }
        return list1;
    }

精彩评论(0)

0 0 举报