public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int firstCount = 0;
        int secondCount = 0;

        //First number of nodes in first list
        ListNode A = headA;
        while (A != null) {
            firstCount = firstCount + 1;
            A = A.next;
        }
        //Find number of nodes in second list
        ListNode B = headB;
        while (B != null) {
            secondCount = secondCount + 1;
            B = B.next;
        }

        if (firstCount > secondCount) {
            int diff = firstCount - secondCount;
            while (diff > 0) {
                headA = headA.next;
                diff = diff - 1;
            }
        } else if (secondCount > firstCount) {
            int diff = secondCount - firstCount;
            while (diff > 0) {
                headB = headB.next;
                diff = diff - 1;
            }
        }

        return getNode(headA, headB);
    }