예제 #1
0
        static ListNode Revese(ListNode head, int k)
        {
            ListNode preNode = head;
            ListNode n1      = head.next;

            if (n1 == null)
            {
                return(null);
            }
            ListNode kNode = preNode;

            for (int i = 0; i < k; i++)
            {
                if (kNode == null)
                {
                    return(null);
                }
                kNode = kNode.next;
            }
            if (kNode == null)
            {
                return(null);
            }
            ListNode kPlus = kNode.next;
            ListNode cur   = n1;

            while (cur != kPlus)
            {
                ListNode temp = cur.next;
                cur.next = preNode;
                preNode  = cur;
                cur      = temp;
            }
            head.next = preNode;
            n1.next   = kPlus;
            return(n1);
        }