@@ -0,0 +1,2453 @@
+package ListNode;%0A%0A//2. Add Two Numbers%0A/**%0A * 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.%0A * %0A * You may assume the two numbers do not contain any leading zero, except the number 0 itself.%0A * %0A * Input: (2 -%3E 4 -%3E 3) + (5 -%3E 6 -%3E 4)%0A * Output: 7 -%3E 0 -%3E 8%0A * %0A * Tags:  Linked List, Math%0A * Similar Problems:  (M) Multiply Strings (E) Add Binary (E) Sum of Two Integers (E) Add Strings (M) Add Two Numbers II%0A * %0A * @author Xinyue Zhang%0A *%0A */%0A%0A//ListNode class%0A/**%0Apackage ListNode;%0A%0Apublic class ListNode %7B%0A    int val;%0A    ListNode next;%0A    ListNode(int x) %7B val = x; %7D%0A    %0A    public static ListNode createList(int val) %7B%0A        ListNode prev = new ListNode(0);%0A        ListNode node = new ListNode(0);%0A        ListNode head = prev;%0A        %0A        node.val = val;%0A        prev.next = node;%0A        prev = node;%0A        %0A        return head.next;%0A    %7D%0A    %0A    public static void insertList(int val, ListNode head) %7B%0A        ListNode node = new ListNode(0);%0A        node.val = val;%0A        while (head.next != null)%0A            head = head.next;%0A        head.next = node;%0A    %7D%0A%7D**/%0A%0Apublic class Solution %7B%0A    public ListNode addTwoNumbers(ListNode l1, ListNode l2) %7B%0A        ListNode prev = new ListNode(0);%0A        ListNode head = prev;%0A        int carry = 0, sum = 0;%0A        %0A        while (l1 != null %7C%7C l2 != null %7C%7C carry != 0) %7B%0A            sum = carry + ((l1 == null) ? 0 : l1.val) + ((l2 == null) ? 0 : l2.val);%0A            carry = sum / 10;%0A            %0A            prev.next = new ListNode(sum %25 10);%0A            prev = prev.next;%0A            %0A            l1 = l1 == null ? l1 : l1.next;%0A            l2 = l2 == null ? l2 : l2.next;%0A        %7D%0A        return head.next;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        ListNode l1 = ListNode.createList(2);%0A        ListNode.insertList(4, l1);%0A        ListNode.insertList(3, l1);%0A        %0A        ListNode l2 = ListNode.createList(5);%0A        ListNode.insertList(6, l2);%0A        ListNode.insertList(4, 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);%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 002 add two numbers