```
public ListNode reverseBetween(ListNode head, int m, int n) {
if (head == null || head.next == null || m == n) {
return head;
}
ListNode pre, dummy = new ListNode(0);
pre = dummy;
dummy.next = head;
for (int i = 0; i < m-1; i++) {
pre = pre.next;
}
ListNode cur = pre.next, p = pre.next, node = null;
for (int i = 0; i <= n-m; i++) {
ListNode nxt = cur.next;
cur.next = node;
node = cur;
cur = nxt;
}
p.next = cur;
pre.next = node;
return dummy.next;
}
```