author: Blankj blog : http://blankj.com time : 2017/10/11 desc :
| 11 | * </pre> |
| 12 | */ |
| 13 | public class Solution { |
| 14 | public ListNode addTwoNumbers(ListNode l1, ListNode l2) { |
| 15 | ListNode node = new ListNode(0); |
| 16 | ListNode n1 = l1, n2 = l2, t = node; |
| 17 | int sum = 0; |
| 18 | while (n1 != null || n2 != null) { |
| 19 | sum /= 10; |
| 20 | if (n1 != null) { |
| 21 | sum += n1.val; |
| 22 | n1 = n1.next; |
| 23 | } |
| 24 | if (n2 != null) { |
| 25 | sum += n2.val; |
| 26 | n2 = n2.next; |
| 27 | } |
| 28 | t.next = new ListNode(sum % 10); |
| 29 | t = t.next; |
| 30 | } |
| 31 | if (sum / 10 != 0) t.next = new ListNode(1); |
| 32 | return node.next; |
| 33 | } |
| 34 | |
| 35 | public static void main(String[] args) { |
| 36 | Solution solution = new Solution(); |
| 37 | ListNode.print(solution.addTwoNumbers( |
| 38 | ListNode.createTestData("[2,4,3]"), |
| 39 | ListNode.createTestData("[5,6,4]") |
| 40 | )); |
| 41 | } |
| 42 | } |
nothing calls this directly
no outgoing calls
no test coverage detected