funcreverseBetween(head *ListNode, left int, right int) *ListNode { if left == 1 { return reverseN(head, right) } head.Next = reverseBetween(head.Next, left-1, right-1) return head }
funcreverseN(head *ListNode, n int) *ListNode { if n == 1 { successor = head.Next return head }
reversed := reverseN(head.Next, n - 1)
head.Next.Next = head head.Next = successor return reversed }