We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d1a9328 commit 350de16Copy full SHA for 350de16
solution/0002.Add Two Numbers/Solution2.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ """
3
+ This solution is from: https://leetcode.com/problems/add-two-numbers/discuss/1102/Python-for-the-win
4
+ A very Pythonic solution, coooooool!
5
+ Runtime: 76 ms, faster than 84.66% of Python3 online submissions for Add Two Numbers.
6
+ Memory Usage: 13.3 MB, less than 38.91% of Python3 online submissions for Add Two Numbers.
7
8
+ def addTwoNumbers(self, l1, l2):
9
+ def toint(node):
10
+ return node.val + 10 * toint(node.next) if node else 0
11
+ def tolist(n):
12
+ node = ListNode(n % 10)
13
+ if n > 9:
14
+ node.next = tolist(n // 10)
15
+ return node
16
+ return tolist(toint(l1) + toint(l2))
0 commit comments