예제 #1
0
        public void AddTwoNumbersTest02()
        {
            ListNode l1 = null;
            ListNode l2 = null;
            var      c  = new AddTwoNumbersClass();

            int[] l1array = { 0 };
            int[] l2array = { 0 };
            for (var i = 0; i < l1array.Length; i++)
            {
                InsertNode(l1array[i], ref l1);
            }
            for (var i = 0; i < l2array.Length; i++)
            {
                InsertNode(l2array[i], ref l2);
            }

            // example1
            var result = c.AddTwoNumbers(l1, l2);

            int[] expected = { 0 };

            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], result.val);
                result = result.next;
            }
            Assert.IsNull(result);
        }
예제 #2
0
        public void AddTwoNumbers()
        {
            var l1 = new ListNode(2);

            l1.next      = new ListNode(4);
            l1.next.next = new ListNode(3);
            var l2 = new ListNode(5);

            l2.next      = new ListNode(6);
            l2.next.next = new ListNode(4);

            var AddTwoNumbersClass = new AddTwoNumbersClass();

            AddTwoNumbersClass.AddTwoNumbers(l1, l2);
        }
예제 #3
0
    private static int LeetCode_TwoNumbers()
    {
        AddTwoNumbersClass.ListNode list1 = new AddTwoNumbersClass.ListNode(1);
        //list1.next = new AddTwoNumbersClass.ListNode(1);
        //list1.next.next = new AddTwoNumbersClass.ListNode(3);

        AddTwoNumbersClass.ListNode list2 = new AddTwoNumbersClass.ListNode(9);
        list2.next = new AddTwoNumbersClass.ListNode(9);
        //list2.next.next = new AddTwoNumbersClass.ListNode(4);

        AddTwoNumbersClass.ListNode listResult = AddTwoNumbersClass.AddTwoNumbers(list1, list2);

        while (listResult != null)
        {
            Console.Write(listResult.val);
            listResult = listResult.next;
        }

        Console.ReadLine();
        return(0);
    }