static void Main(string[] args) { //Solution solution = new Solution(); //int[] nums = new int[4] { 11, 15, 2, 7 }; //int[] result=solution.TwoSum(nums, 9); //foreach(var item in result) //{ // Console.WriteLine(item); //} LeetCode2 solution = new LeetCode2(); ListNode node1 = new ListNode(9); node1.next = new ListNode(8); node1.next.next = null; ListNode node2 = new ListNode(1); node2.next = null; ListNode result = solution.AddTwoNumbers(node1, node2); while (result != null) { Console.Write(result.val); result = result.next; } Console.ReadLine(); }
public void AddTwoNumbers_TwoNonEmptyLinkedList_ExpectSumOfValue() { ListNodeLc2 list1 = new ListNodeLc2(2); list1.Next = new ListNodeLc2(4); list1.Next.Next = new ListNodeLc2(3); ListNodeLc2 list2 = new ListNodeLc2(5); list2.Next = new ListNodeLc2(6); list2.Next.Next = new ListNodeLc2(4); ListNodeLc2 list3 = new ListNodeLc2(7); list3.Next = new ListNodeLc2(0); list3.Next.Next = new ListNodeLc2(8); var result = LeetCode2.AddTwoNumbers(list1, list2); while (result != null || list3 != null) { Assert.AreEqual(list3.Value, result.Value); result = result.Next; list3 = list3.Next; } }