Problem:
Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
-Summary-
1. Keep track of current / prev (copy the original list in the curr and prev)
2. Update and move the head (original)
3. Return prev
정답을 보니 recursive 하게 푸는 방법도 있었다.
모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]
'LeetCode > Problems' 카테고리의 다른 글
LeetCode 2. Add Two Numbers [Linked List] (0) | 2020.06.09 |
---|---|
LeetCode 21. Merge Two Sorted Lists (0) | 2020.06.01 |
LeetCode 876. Middle of the Linked List (0) | 2020.05.31 |
LeetCode 1290. Convert Binary Number in a Linked List to Integer (0) | 2020.05.31 |
LeetCode 242. Delete Node in a Linked List (0) | 2020.05.31 |
댓글