多个指针,让cur倒过来得到结果
/** * 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) { ListNode *root = new ListNode(0); root->next = head; ListNode *p = root; for(int i = 0; i < m-1; i++) p = p->next; ListNode *h = p; p = h->next; ListNode *cur = p->next; for(int i = m; i < n; i++){ p->next = cur->next; cur->next =h->next; h->next = cur; cur = p->next; } return root->next; } };