public ListNode getIntersectionNode2(ListNode x, ListNode y) {
        if(x==null || y==null)return null;

        ListNode xhead=x;
        ListNode yhead=y;

        while (xhead != yhead){
            xhead = xhead == null ? y : xhead.next;
            yhead = yhead == null ? x : yhead.next;
        }
        return xhead;
    }
This is another iterative solution without knowing size of lists.
We can use two iterations to do that. In the first iteration, we will reset the pointer of one
linked list to the head of another linked list after it reaches the tail node. In the second
iteration, we will move two pointers until they points to the same node. Our operations in first
iteration will help us counteract the difference. So if two linked list intersects,
the meeting point in second iteration must be the intersection point. If the two linked lists
have no intersection at all, then the meeting pointer in second iteration must be the tail
node of both lists, which is null
src/problems/easy/IntersectionofTwoLinkedLists.java