0206 Reverse Linked List
Warning
This post is more than a year old. Information may be outdated.
Solved at: 230128 Reverse Linked List
Question
Given the head of a singly linked list, reverse the list, and return the reversed list.
Solution
causes time limit exceeded
Improved
i was like -- what -- why?
then I figured it was because the last two elements, previously head, had an infinite loop. therefore, the printing answer part caused the error.
Results
- Runtime 12 ms, Beats 81.49%
- Memory 15 MB, Beats 45.31%
Complexity Analysis
Time Space
Other Answers Online
Recursive approach
- Runtime 12 ms, Beats 81.49%
- Memory 14.6 MB, Beats 91.58%
Backlinks1
Coding Tests