@Test public void test() { linkedList=new IntersactionOfLinkedList(); ListNode headA = new ListNode(1); headA.next = new ListNode(2); headA.next.next = new ListNode(4); headA.next.next.next = new ListNode(5); headA.next.next.next.next = new ListNode(6); ListNode headB = new ListNode(11); headB.next = new ListNode(22); headB.next.next = new ListNode(13); headB.next.next.next = new ListNode(4); headB.next.next.next.next = new ListNode(5); headB.next.next.next.next.next = new ListNode(6); ListNode op= linkedList.getIntersectionNode(headA, headB); Assertions.assertEquals(4,op.val); }
public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int lenA=len(headA); System.out.println(lenA); int lenB=len(headB); if(lenA>lenB){ headA=findNewHead(Math.abs(lenA-lenB),headA); }else { headB=findNewHead(Math.abs(lenA-lenB),headB); } System.out.println(" "); while (headA!=null && headB!=null){ if(headA.val==headB.val){ return headA; }else { headA=headA.next; headB=headB.next; } } return null; }
IntersactionOfLinkedList { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int lenA=len(headA); System.out.println(lenA); int lenB=len(headB); if(lenA>lenB){ headA=findNewHead(Math.abs(lenA-lenB),headA); }else { headB=findNewHead(Math.abs(lenA-lenB),headB); } System.out.println(" "); while (headA!=null && headB!=null){ if(headA.val==headB.val){ return headA; }else { headA=headA.next; headB=headB.next; } } return null; } }
IntersactionOfLinkedList { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int lenA=len(headA); System.out.println(lenA); int lenB=len(headB); if(lenA>lenB){ headA=findNewHead(Math.abs(lenA-lenB),headA); }else { headB=findNewHead(Math.abs(lenA-lenB),headB); } System.out.println(" "); while (headA!=null && headB!=null){ if(headA.val==headB.val){ return headA; }else { headA=headA.next; headB=headB.next; } } return null; }  }
IntersactionOfLinkedList { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int lenA=len(headA); System.out.println(lenA); int lenB=len(headB); if(lenA>lenB){ headA=findNewHead(Math.abs(lenA-lenB),headA); }else { headB=findNewHead(Math.abs(lenA-lenB),headB); } System.out.println(" "); while (headA!=null && headB!=null){ if(headA.val==headB.val){ return headA; }else { headA=headA.next; headB=headB.next; } } return null; }  ListNode getIntersectionNode(ListNode headA,
                                        ListNode headB); }
IntersactionOfLinkedList { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { int lenA=len(headA); System.out.println(lenA); int lenB=len(headB); if(lenA>lenB){ headA=findNewHead(Math.abs(lenA-lenB),headA); }else { headB=findNewHead(Math.abs(lenA-lenB),headB); } System.out.println(" "); while (headA!=null && headB!=null){ if(headA.val==headB.val){ return headA; }else { headA=headA.next; headB=headB.next; } } return null; }  ListNode getIntersectionNode(ListNode headA,
                                        ListNode headB);  }