无码萌妹码代码

Reverse a linked list from position m to n. Do it in-place and in one-pass.
For example:
Given 1->2->3->4->5->NULL, m = 2 and n = 4,
return 1->4->3->2->5->NULL.

struct ListNode* reverseBetween(struct ListNode* head, int m, int n) {
int i = 1;
for (struct ListNode* node = head; node; node = node->next, i++) {
if (i == m)
mPtr = node;
if (i == n)
nPtr = node;
}
while (mPtr != nPtr) {
struct ListNode* temp = mPtr;
mPtr = mPtr->next;
temp->next = nPtr->next;
nPtr->next = temp;
}
return nPtr;
}
else {
while (mPtrPrev->next != mPtr)
mPtrPrev = mPtrPrev->next;
mPtrPrev->next = nPtr;
while (mPtr != nPtr) {
struct ListNode* temp = mPtr;
mPtr = mPtr->next;
temp->next = nPtr->next;
nPtr->next = temp;
}
}
}

0ms，100%
Cmershen的碎碎念：

2015-12-26 16:14:34

【LeetCode】92. Reverse Linked List II 解题报告

2017-03-28 09:42:23

2014-01-28 01:06:19

Reverse Linked List II -- LeetCode

2014-04-28 04:58:33

2016-09-18 21:54:15

2014-01-28 11:06:09

2015-05-14 06:47:30

2014-12-05 15:59:28

2016-02-19 13:39:20

2017-08-07 13:57:36