struct ListNode
{
int val;
ListNode *next;
ListNode(int x = 0) : val(x), next(NULL) {}
};
ListNode *ReverseBetween(ListNode *head, int m, int n)
{
ListNode** h = &head;
n = n-m+1;
while(--m > 0)h = &((*h)->next);
ListNode* cur = *h;
ListNode* pre = NULL;
ListNode* nxt;
while(n-- > 0)
{
nxt = cur->next;
cur->next = pre;
pre = cur;
cur = nxt;
}
(*h)->next = cur;
*h = pre;
return head;
}