public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode a = headA, b = headB;
        while (a != null && b != null && a != b) {
            a = a.next;
            b = b.next;
            if (a == b) return a;
            if (b == null) b = headA;
            if (a == null) a = headB;
        }
        return a;
    }