Created
April 9, 2017 11:39
-
-
Save linnykoleh/af529290f80a9ba9e6f6d0a71a912576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static ListNode getIntersectionNode(ListNode headA, ListNode headB) { | |
if(headA == null || headB == null){ | |
return null; | |
} | |
final Set<ListNode> nodesA = new HashSet<>(); | |
ListNode currentA = headA; | |
ListNode currentB = headB; | |
while (currentA != null){ | |
nodesA.add(currentA); | |
currentA = currentA.next; | |
} | |
while (currentB != null){ | |
if(nodesA.contains(currentB)){ | |
return currentB; | |
} | |
currentB = currentB.next; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment