public void Main(string args)
    {
        string arg_str = args.Replace("[[", "").Replace("]]", "").Trim();

        string[] flds = arg_str.Split(new string[] { "],[" }, StringSplitOptions.None);

        int[][] nums = new int[flds.Length][];
        for (int i = 0; i < nums.Length; ++i)
        {
            nums[i] = str_to_int_array(flds[i]);
            Console.WriteLine("nums[" + i.ToString() + "] = " + output_int_array(nums[i]));
        }

        Operate_ListNode ope = new Operate_ListNode();

        ListNode[] lists = new ListNode[nums.Length];

        for (int i = 0; i < nums.Length; ++i)
        {
            lists[i] = ope.set_ListNode(nums[i]);
            Console.WriteLine("lists[" + i.ToString() + "] = " + ope.output_ListNode(lists[i]));
        }

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        ListNode result = MergeKLists(lists);

        sw.Stop();

        Console.WriteLine("result = " + ope.output_ListNode(result));
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
Пример #2
0
    public void Main(string args)
    {
        string arg_str = args.Replace("[[", "").Replace("]]", "").Trim();

        string[] flds = arg_str.Split(new string[] { "],[" }, StringSplitOptions.None);
        int[]    num1 = str_to_int_array(flds[0]);
        int[]    num2 = str_to_int_array(flds[1]);
        Console.WriteLine("num1 = " + output_int_array(num1));
        Console.WriteLine("num2 = " + output_int_array(num2));

        Operate_ListNode ope = new Operate_ListNode();
        ListNode         l1  = ope.set_ListNode(num1);
        ListNode         l2  = ope.set_ListNode(num2);

        Console.WriteLine("l1 = " + ope.output_ListNode(l1));
        Console.WriteLine("l2 = " + ope.output_ListNode(l2));

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        ListNode result = AddTwoNumbers(l1, l2);

        Console.WriteLine("result = " + ope.output_ListNode(result));

        sw.Stop();
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
Пример #3
0
    public void Main(string args)
    {
        string arg_str = args.Replace("[", "").Replace("]", "").Trim();

        int[] nums = str_to_int_array(arg_str);
        Console.WriteLine("nums = " + output_int_array(nums));

        Operate_ListNode ope  = new Operate_ListNode();
        ListNode         head = ope.set_ListNode(nums);

        Console.WriteLine("head = " + ope.output_ListNode(head));

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        ListNode result = SwapPairs(head);

        sw.Stop();
        Console.WriteLine("result = " + ope.output_ListNode(result));
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
Пример #4
0
    public void Main(string args)
    {
        string flds = args.Replace("[", "").Replace("]", "");

        int[] nums = str_to_int_array(flds);

        Operate_ListNode ope  = new Operate_ListNode();
        ListNode         node = ope.set_ListNode(nums);

        Console.WriteLine("node = " + ope.output_ListNode(node));

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        ListNode result_node = ReverseList(node);

        Console.WriteLine("Result = " + ope.output_ListNode(result_node));

        sw.Stop();
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
Пример #5
0
    public void Main(string args)
    {
        string[] flds = args.Replace(" ", "").Replace("[[", "").Replace("]]", "").Split("],[", StringSplitOptions.None);
        int[]    nums = str_to_int_array(flds[0]);
        int      k    = int.Parse(flds[1]);

        Operate_ListNode ope  = new Operate_ListNode();
        ListNode         node = ope.set_ListNode(nums);

        Console.WriteLine("node = " + ope.output_ListNode(node));

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        ListNode result_node = RemoveElements(node, k);

        sw.Stop();

        Console.WriteLine("Result = " + ope.output_ListNode(result_node));
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
Пример #6
0
    public void Main(string args)
    {
        Console.WriteLine("args = " + args );
        string[] flds = args.Replace("\"", "").Replace("[[", "").Replace("]]", "").Trim().Split("],[", StringSplitOptions.None);
        int[] nums1 = str_to_int_array(flds[0]);
        int[] nums2 = str_to_int_array(flds[1]);

        Operate_ListNode ope = new Operate_ListNode();
        ListNode node = ope.set_ListNode(nums1);

        Console.WriteLine("node = " + ope.output_ListNode(node));

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        DeleteNode(node);
        Console.WriteLine("node = " + ope.output_ListNode(node));

        sw.Stop();
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }