package leetcode;

/**
 * https://leetcode.com/problems/add-two-numbers-ii/
 */
public class Problem445 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        Num n1 = getNumber(l1);
        Num n2 = getNumber(l2);
        long sum = n1.n + n2.n;
        // TODO
        return null;
    }

    private static class Num {
        private long n;
        private int digit;

        public Num(long n, int digit) {
            this.n = n;
            this.digit = digit;
        }
    }

    private static Num getNumber(ListNode node) {
        if (node == null) {
            return new Num(0, 1);
        }
        Num num = getNumber(node.next);
        num.n += (node.val * num.digit);
        num.digit *= 10;
        return num;
    }

    public static void main(String[] args) {
        Problem445 prob = new Problem445();
        ListNode l1 = new ListNode(7);
        l1.next = new ListNode(2);
        l1.next.next = new ListNode(4);
        l1.next.next.next = new ListNode(3);

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

        System.out.println(prob.addTwoNumbers(l1, l2));
    }
}

@@ -12,16 +12,46 @@
 tcode;%0A%0A
+import java.math.BigInteger;%0A%0A
 /**%0A * h
@@ -407,47 +407,409 @@
     
-long sum = n1.n + n2.n;%0A        // TODO
+char%5B%5D sum = n1.n.add(n2.n).toString().toCharArray();%0A        ListNode head = null;%0A        ListNode node = null;%0A        for (int i = 0; i %3C sum.length; i++) %7B%0A            if (i == 0) %7B%0A                head = new ListNode(sum%5Bi%5D - '0');%0A                node = head;%0A            %7D else %7B%0A                node.next = new ListNode(sum%5Bi%5D - '0');%0A                node = node.next;%0A            %7D%0A        %7D
 %0A   
@@ -820,20 +820,20 @@
  return 
-null
+head
 ;%0A    %7D%0A
@@ -880,20 +880,26 @@
 private 
-long
+BigInteger
  n;%0A    
@@ -910,19 +910,26 @@
 private 
-int
+BigInteger
  digit;%0A
@@ -952,19 +952,32 @@
 Num(
-long n, int
+BigInteger n, BigInteger
  dig
@@ -1164,12 +1164,39 @@
 Num(
-0, 1
+BigInteger.ZERO, BigInteger.ONE
 );%0A 
@@ -1262,23 +1262,58 @@
 m.n 
-+
 = 
-(node.val * 
+num.n.add(BigInteger.valueOf(node.val).multiply(
 num.
@@ -1318,16 +1318,17 @@
 m.digit)
+)
 ;%0A      
@@ -1343,414 +1343,54 @@
 git 
-*
 = 
-10;%0A        return num;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem445 prob = new Problem445();%0A        ListNode l1 = new ListNode(7);%0A        l1.next = new ListNode(2);%0A        l1.next.next = new ListNode(4);%0A        l1.next.next.next = new ListNode(3);%0A%0A        ListNode l2 = new ListNode(5);%0A        l2.next = new ListNode(6);%0A        l2.next.next = new ListNode(4
+num.digit.multiply(BigInteger.TEN
 );%0A
-%0A
         
 Syst
@@ -1389,54 +1389,18 @@
     
-System.out.println(prob.addTwoNumbers(l1, l2))
+return num
 ;%0A  

Solve problem 445