[LeetCode] 92. Reverse Linked List II
- Total Accepted: 106086
- Total Submissions: 350637
- Difficulty: Medium
- Contributor: LeetCode
Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given
Given
1->2->3->4->5->NULL
, m = 2 and n = 4,
return
1->4->3->2->5->NULL
.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
思路:
1. 先移到 m-1 的位置
2. 反轉之後的 n-m 個 節點
3. 連結舊的 和 新的 list
留言
張貼留言