Problem
Follow up
A linked list can be reversed either iteratively or recursively. Could you implement both?
Java
iteratively
1
© LeetCode – Reverse Linked List (Java) - Java Solution 1 - Iterative
1 | /** |
Submission Detail
- 27 / 27 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Reverse Linked List.
- Memory Usage: 39 MB, less than 22.36% of Java online submissions for Reverse Linked List.
2
1 | /** |
Submission Detail
- 27 / 27 test cases passed.
- Runtime: 0 ms
- Your runtime beats 100.00 % of java submissions.
recursively
1
© LeetCode – Reverse Linked List (Java) - Java Solution 2 - Recursive
1 | /** |
Submission Detail
- 27 / 27 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Reverse Linked List.
- Memory Usage: 39.2 MB, less than 22.97% of Java online submissions for Reverse Linked List.
2
1 | /** |
Submission Detail
- 27 / 27 test cases passed.
- Runtime: 1 ms
- Your runtime beats 6.80 % of java submissions.
Tail Recursive
1 | /** |
Submission Detail
- 27 / 27 test cases passed.
- Runtime: 0 ms
- Your runtime beats 100.00 % of java submissions.