/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @param m int整型
* @param n int整型
* @return ListNode类
*/
struct ListNode* reverseBetween(struct ListNode* head, int m, int n ) {
if(!head || m == n) return head;
struct ListNode* t = malloc(sizeof(struct ListNode));
t->val = -1;
t->next = head;
struct ListNode* p = t;
for(int i = 1; i < m; i++) {
p = p->next;
}
struct ListNode* c = p->next;
for(int i = 0; i < n - m; i++) {
struct ListNode* n = c->next;
c->next = n->next;
n->next = p->next;
p->next = n;
}
return t->next;
}