Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListNode* reverseBetween(ListNode* head, int m, int n) {
- if(m==n)return head;
- n-=m;
- ListNode*tmp=new ListNode(0);
- tmp->next=head;
- ListNode*pre=tmp,*cur;
- while(--m)pre=pre->next;
- cur=pre->next;
- ListNode*next=cur->next;
- while(n--)
- {
- next=cur->next;
- cur->next=next->next;
- next->next=pre->next;
- pre->next=next;
- }
- return tmp->next;
- }
Add Comment
Please, Sign In to add comment