@@ -0,0 +1,1765 @@
+package miscellaneous.math.arithmetic.lc445_addtwonumbers2;%0A%0Aimport fundamentals.list.ListNode;%0A%0Aimport java.util.Stack;%0A%0A/**%0A * %0A */%0Apublic class Solution %7B%0A%0A    // Generate reversed list directly%0A    // nil,nil  1,nil  1,2  1,9  1,9-%3E9  1-%3E2,3-%3E4-%3E5%0A    public ListNode addTwoNumbers(ListNode l1, ListNode l2) %7B%0A        Stack%3CInteger%3E s1 = new Stack%3C%3E(), s2 = new Stack%3C%3E();%0A        for (; l1 != null; l1 = l1.next) s1.push(l1.val);%0A        for (; l2 != null; l2 = l2.next) s2.push(l2.val);%0A%0A        ListNode pre = null;%0A        int carry = 0;%0A        while (!s1.isEmpty() %7C%7C !s2.isEmpty() %7C%7C carry != 0) %7B%0A            int v1 = s1.isEmpty() ? 0 : s1.pop();%0A            int v2 = s2.isEmpty() ? 0 : s2.pop();%0A            int sum = v1 + v2 + carry;%0A            carry = sum / 10;%0A            ListNode cur = new ListNode(sum %25 10);%0A            cur.next = pre;%0A            pre = cur;%0A        %7D%0A        return pre;%0A    %7D%0A%0A    public ListNode addTwoNumbers_my(ListNode l1, ListNode l2) %7B%0A        Stack%3CInteger%3E s1 = new Stack%3C%3E(), s2 = new Stack%3C%3E();%0A        for (; l1 != null; l1 = l1.next) s1.push(l1.val);%0A        for (; l2 != null; l2 = l2.next) s2.push(l2.val);%0A%0A        ListNode dmy = new ListNode(0), pre = dmy;%0A        int carry = 0;%0A        while (!s1.isEmpty() %7C%7C !s2.isEmpty() %7C%7C carry != 0) %7B%0A            int v1 = s1.isEmpty() ? 0 : s1.pop();%0A            int v2 = s2.isEmpty() ? 0 : s2.pop();%0A            int sum = v1 + v2 + carry;%0A            pre = pre.next = new ListNode(sum %25 10);%0A            carry = sum / 10;%0A        %7D%0A%0A        pre = null;%0A        ListNode cur = dmy.next;%0A        while (cur != null) %7B%0A            ListNode suc = cur.next;%0A            cur.next = pre;%0A            pre = cur;%0A            cur = suc;%0A        %7D%0A        return pre;%0A    %7D%0A%0A%7D%0A

add two numbers II