/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseBetween(ListNode* head, int m, int n) {
auto dummy = new ListNode(-1);
dummy->next = head;
auto a = dummy;
for (int i = 0; i < m - 1; ++i) a = a->next;
auto b = a->next, c = b->next;
for (int i = 0; i < n - m; ++i) {
auto t = c->next;
c->next = b;
b = c, c = t;
}
a->next->next = c;
a->next = b;
return dummy->next;
}
};
原文:https://www.cnblogs.com/clown9804/p/13325137.html