public static void MergeKListsProblem() { var lists = new ListNode[] { new ListNode(1) { next = new ListNode(4) { next = new ListNode(5) } }, new ListNode(1) { next = new ListNode(3) { next = new ListNode(4) } }, new ListNode(2) { next = new ListNode(6) } }; CrudOps.PrintList(MergeKLists(lists)); }
/// <summary> /// You are given two non-empty linked lists representing two non-negative integers. /// The digits are stored in reverse order and each of their nodes contain a single digit. /// Add the two numbers and return it as a linked list. /// /// You may assume the two numbers do not contain any leading zero, except the number 0 itself. /// /// Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) /// Output: 7 -> 0 -> 8 /// Explanation: 342 + 465 = 807. /// </summary> /// <returns>The calculated list</returns> /// <param name="l1">List 1</param> /// <param name="l2">List 2</param> public static void AddTwoNumbersProblem() { var list1 = new ListNode(2) { next = new ListNode(4) { next = new ListNode(3) } }; var list2 = new ListNode(5) { next = new ListNode(6) { next = new ListNode(4) } }; CrudOps.PrintList(AddTwoNumbers(list1, list2, 0)); list1 = new ListNode(6) { next = new ListNode(4) { next = new ListNode(7) } }; list2 = new ListNode(5) { next = new ListNode(6) { next = new ListNode(4) } }; CrudOps.PrintList(AddTwoNumbers(list1, list2, 0)); list1 = new ListNode(3) { next = new ListNode(4) { next = new ListNode(2) { next = new ListNode(7) } } }; list2 = new ListNode(4) { next = new ListNode(6) { next = new ListNode(5) { next = new ListNode(1) } } }; CrudOps.PrintList(AddTwoNumbers(list1, list2, 0)); }