ListNode* reverseBetween(ListNode* head, int m, int n){ if (m == n)return head; ListNode* prehead = new ListNode(0); prehead->next = head; int i = m; ListNode* front = prehead; while (i) { front = front->next; i--; } stack<int> s; ListNode* back; back = front; int k = n - m; while (k) { s.push(back->val); back = back->next; k--; } s.push(back->val); while (!s.empty()) { front->val = s.top(); s.pop(); front = front->next; } return prehead->next; }