/
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode next) : val(x), next(next) {}
* };
/
class Solution {
public:
ListNode reverseBetween(ListNode* head, int left, int right) {
auto p1=new ListNode(-1);
p1->next=head;
auto p=p1;
int i=0;
while(p&&i[HTML_REMOVED]next;
i;
}
auto q=p->next;
auto h=q->next;
while(i[HTML_REMOVED]next;
h->next=q;
q=h;
h=w;
i;
}
p->next->next=h;
p->next=q;
auto res=p1->next;
delete p1;
return res;
}
};