public ListNode reverseBetween(ListNode head, int m, int n) {
        if (head == null || head.next == null)
            return head;
        ListNode res = new ListNode(-1);
        res.next = head;
        ListNode ptr = res;
        while (m-- > 1) {
            head = head.next;
            ptr = ptr.next;
            --n;
        }
        ListNode t = ptr;
        while (n-- >= 1) {
            ListNode temp = head.next;
            head.next = ptr;
            ptr = head;
            head = temp;
        }
        t.next.next = head;
        t.next = ptr;
        return res.next;
    }