public static LeetCode92ListNode ReverseBetween(LeetCode92ListNode head, int left, int right) { if (left == 1) { return(ReverseN(head, right)); } head.next = ReverseBetween(head.next, left - 1, right - 1); return(head); }
private static LeetCode92ListNode ReverseN(LeetCode92ListNode head, int n) { if (n == 1) { Successor = head.next; return(head); } var last = ReverseN(head.next, n - 1); head.next.next = last; head.next = Successor; return(last); }
public LeetCode92ListNode(int val = 0, LeetCode92ListNode next = null) { this.val = val; this.next = next; }