• 26.7%

You are given two linked lists representing two non-negative numbers. 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.

### 方法一：

40ms, 24.98%, 17 July 2016

https://discuss.leetcode.com/topic/5905/c-sharing-my-11-line-c-solution-can-someone-make-it-even-more-concise/4

#### python

https://discuss.leetcode.com/topic/21192/python-concise-solution

188ms, 7.15%, 17 July 2016

Python concise solution.

https://discuss.leetcode.com/topic/8909/clear-python-code-straight-forward

172ms, 15.49%, 17 July 2016

Clear python code, straight forward

https://discuss.leetcode.com/topic/8909/clear-python-code-straight-forward

https://discuss.leetcode.com/topic/14575/python-for-the-win

Python for the win

Python supports arbitrarily large integers, so I can safely turn the two lists into ints, add them, and turn the sum into a list.

And a very different solution that could sum arbitrarily many addends, not just two:

#### java

Time complexity : O(\max(m, n))O(max(m,n)). Assume that mm and nn represents the length of l1l1 and l2l2 respectively, the algorithm above iterates at most \max(m, n)max(m,n) times.

Space complexity : O(\max(m, n))O(max(m,n)). The length of the new list is at most \max(m,n) + 1max(m,n)+1.

https://discuss.leetcode.com/topic/799/is-this-algorithm-optimal-or-what

Is this Algorithm optimal or what?

https://discuss.leetcode.com/topic/6220/my-accepted-java-solution

My accepted Java solution

Two things to make the code simple:

1. Whenever one of the two ListNode is null, replace it with 0.
2. Keep the while loop going when at least one of the three conditions is met.

Let me know if there is something wrong. Thanks.

https://discuss.leetcode.com/topic/39130/4ms-11lines-java-solution

4ms 11lines java solution

https://discuss.leetcode.com/topic/44133/java-concise-solution

Java concise solution.