【leetcode】92. 反转链表 II
struct ListNode* reverseBetween(struct ListNode* head, int m, int n){ if (m == n) return head; struct ListNode* root = (struct ListNode*)calloc(sizeof(struct ListNode), 1); struct ListNode* left, *next, *pre=root; root->next = head; int cnt = 0; while (++cnt <= n){ next = head->next; if (cnt > m && cnt <= n){ head->next = pre; } else if (cnt == m) left = pre; pre = head; head = next; } left->next->next = head; left->next = pre; return root->next; }