/**
* 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) {
if(m==n) return head;
ListNode *p=new ListNode(0),*low=p,*high,*q,*pre;
p->next=head,n-=m;
while(--m) low=low->next;
high=low->next->next,pre=low->next;
while(n--) q=high->next,high->next=pre,pre=high,high=q;
low->next->next=high,low->next=pre;
head=p->next;
delete(p);
return head;
}
};