Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public LeetCode92ListNode(int val = 0, LeetCode92ListNode next = null)
 {
     this.val  = val;
     this.next = next;
 }