编程语言
首页 > 编程语言> > 160. 相交链表 Java版

160. 相交链表 Java版

作者:互联网

/**
 * 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 pA = headA, pB = headB;

        while( pA != pB ){

            pA = pA == null ? headB : pA.next;

            pB = pB == null ? headA : pB.next;

        }

        return pA;

    }
}

标签:pB,ListNode,链表,pA,headB,headA,Java,null,160
来源: https://blog.csdn.net/CSDNer_zry/article/details/120624745