import java.util.*; public class Solution { public ListNode reverseBetween (ListNode head, int m, int n) { // write code here if(head==null||head.next==null||m==n) return head; ListNode newHead = new ListNode(0); ListNode pre = newHead; pre.next = head; for(int i = 1 ; i < m ; i++){ pre = pre.next; } ListNode cur = pre.next; for(int i = m ; i < n ;i++){ ListNode temp = cur.next; cur.next = temp.next; temp.next = pre.next; pre.next = temp; } return newHead.next; } }