public static ListNode reverseBetween2(ListNode head, int m, int n) {

    if (head == null) {
      return head;
    }

    ListNode dummyNode = new ListNode(0);
    dummyNode.next = head;

    int i = 1;
    ListNode prev = dummyNode;
    while (i < m) {
      prev = prev.next;
      i++;
    }

    ListNode tail = prev.next;
    ListNode curt = tail.next;
    while (i < n) {

      tail.next = curt.next;
      curt.next = prev.next;
      prev.next = curt;

      curt = tail.next;
      i++;
    }

    return dummyNode.next;
  }