0
点赞
收藏
分享

微信扫一扫

LeetCode 160. 相交链表

尤克乔乔 2022-02-07 阅读 123

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 条评论