@@ -0,0 +1,2318 @@
+package Solution;%0A%0Aimport java.util.ArrayList;%0A%0A//445. Add Two Numbers II%0A/**%0A * You are given two non-empty linked lists representing two non-negative integers. %0A * The most significant digit comes first and each of their nodes contain a single digit. %0A * Add the two numbers and return it as a linked list.%0A * %0A * You may assume the two numbers do not contain any leading zero, except the number 0 itself.%0A * %0A * Follow up:%0A * What if you cannot modify the input lists? In other words, reversing the lists is not allowed.%0A * %0A * Example:%0A * Input: (7 -%3E 2 -%3E 4 -%3E 3) + (5 -%3E 6 -%3E 4)%0A * Output: 7 -%3E 8 -%3E 0 -%3E 7%0A * %0A * Tags: Linked List%0A * Similar Problems: (M) Add Two Numbers%0A * %0A * @author Xinyue Zhang%0A *%0A */%0A%0A//ListNode class%0A//package Solution;%0A//%0A//public class ListNode %7B%0A//    int val;%0A//    ListNode next;%0A//    ListNode(int x) %7B val = x; %7D%0A//    ListNode(int x, ListNode node) %7B val = x; next = node; %7D %0A//%7D%0A%0Apublic class Solution %7B%0A    public ListNode addTwoNumbers(ListNode l1, ListNode l2) %7B%0A        ArrayList%3CInteger%3E num1 = new ArrayList%3CInteger%3E();%0A        ArrayList%3CInteger%3E num2 = new ArrayList%3CInteger%3E();%0A        while (l1 != null) %7B%0A            num1.add(l1.val);%0A            l1 = l1.next;%0A        %7D%0A        while (l2 != null) %7B%0A            num2.add(l2.val);%0A            l2 = l2.next;%0A        %7D%0A        ListNode head = new ListNode(0);%0A%0A        int i = num1.size() - 1, j = num2.size() - 1, carry = 0;%0A        %0A        while (i %3E= 0 %7C%7C j %3E= 0) %7B%0A            int sum = 0;%0A            if (i != -1) sum += num1.get(i--);%0A            if (j != -1) sum += num2.get(j--);%0A            %0A            head.val = (sum + carry) %25 10;%0A            carry = (sum + carry) / 10;%0A            ListNode dummy = new ListNode(carry);%0A            dummy.next = head;%0A            head = dummy;%0A        %7D%0A        %0A        return head.val == 0 ? head.next : head;   %0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        ListNode l1 = new ListNode(1);%0A        %0A        ListNode l2 = new ListNode(9), l2_1 = new ListNode(9, l2);%0A        %0A        System.out.println(%22Sum = %22);%0A        ListNode sum = new ListNode(0);%0A        Solution sol = new Solution();%0A        sum = sol.addTwoNumbers(l1, l2_1);%0A        while (sum != null) %7B%0A            System.out.println(sum.val);%0A            sum = sum.next;%0A        %7D%0A    %7D%0A%7D%0A

Add solution for 445. Add Two Numbers II