public ListNode(int x) { val = x; }
public ListNode AddTwoNumbers(ListNode l1, ListNode l2)
int result = CollapseToNumber(l1) + CollapseToNumber(l2);
return ConvertToList(result);
public static int CollapseToNumber(ListNode node)
result += (int)(current.val * Math.Pow(10, (double)index));
public static ListNode ConvertToList(int number)
number = (int)(number / 10);
ListNode node = new ListNode(pop);
public static void Main()
Console.WriteLine(a.GetType().FullName);
Console.WriteLine(a + b);
ListNode value1 = Solution.ConvertToList(9);
ListNode value2 = Solution.ConvertToList(1999999999);
ListNode answer = new Solution().AddTwoNumbers(value1, value2);
Console.WriteLine(PrintListNode(value1));
Console.WriteLine(PrintListNode(value2));
Console.WriteLine(PrintListNode(answer));
public static StringBuilder PrintListNode(ListNode node, StringBuilder msg = null)
msg = new StringBuilder();
PrintListNode(node.next, msg);