Problem
160. Intersection of Two Linked Lists
Notes
- If the two linked lists have no intersection at all, return null.
- The linked lists must retain their original structure after the function returns.
- Your code should preferably run in O(n) time and use only O(1) memory.
Java
my solution of O(n) time and O(1) memory
1 | /** |
Submission Detail
- 46 / 46 test cases passed.
- Runtime: 1 ms, faster than 98.53% of Java online submissions for Intersection of Two Linked Lists.
- Memory Usage: 41.7 MB, less than 10.90% of Java online submissions for Intersection of Two Linked Lists.
stack
1 | import java.util.Deque; |
Submission Detail
- 46 / 46 test cases passed.
- Runtime: 2 ms, faster than 38.55% of Java online submissions for Intersection of Two Linked Lists.
- Memory Usage: 42.6 MB, less than 11.53% of Java online submissions for Intersection of Two Linked Lists.