public static ListNode reverseBetween(ListNode head, int m, int n) {
        if(head == null || head.next == null || m == n) return head;

        ListNode left = new ListNode(-1);
        left.next = head;
        for(int i = 1; i < m; i++) left = left.next;

        ListNode rHead = left.next;
        ListNode prev = left.next;
        ListNode curr = prev.next;

        int step = n - m;
        while(curr != null && step != 0){
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
            step--;
        }

        left.next = prev;
        rHead.next = curr;
        return m == 1 ? prev : head;
    }