public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * @param head ListNode类
     * @param m    int整型
     * @param n    int整型
     * @return ListNode类
     */
    public ListNode reverseBetween(ListNode head, int m, int n) {
        if (m == n) {
            return head;
        }
        if(m<=1) {
            return reverse(head, n);
        }
        ListNode newHead = reverseBetween(head.next, m-1, n-1);
        head.next = newHead;
        return head;
    }

    public ListNode reverse(ListNode head, int n) {
        if (n<=1) {
            return head;
        }
        ListNode next = head.next;
        ListNode newHead = reverse(head.next, n-1);
        head.next = next.next;
        next.next = head;
        return newHead;
    }
}

递归法:分为两部分:找起始节点递归,翻转区间递归