import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类
* @param m int整型
* @param n int整型
* @return ListNode类
*/
public ListNode reverseBetween (ListNode head, int m, int n) {
if (head == null || n < m || n == 0) {
return head;
}
ListNode reverseNode = new ListNode(0);
reverseNode.next = head;
ListNode pre = reverseNode;
for (int i = 1; i < m; i++) {
pre = pre.next;
}
ListNode curr = pre.next;
while (n-- > m) {
ListNode temp = curr.next;
curr.next = temp.next;
temp.next = pre.next;
pre.next = temp;
}
return reverseNode.next;
}
}