翻转链表思路
代码
class Solution {
public ListNode reverseBetween(ListNode head, int m, int n) {
ListNode dummy = new ListNode();
dummy.next = head;
ListNode a = dummy;
for(int i = 0; i < m-1; i++) a = a.next;
ListNode b = a.next, c = b.next;
for(int i = 0; i < n-m; i++) {
ListNode t = c.next;
c.next = b;
b = c; c = t;
}
a.next.next = c;
a.next = b;
return dummy.next;
}
}