File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change
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 ))
Original file line number Diff line number Diff line change 19
19
│ ├── Solution.js
20
20
│ ├── Solution.py
21
21
│ ├── Solution.rb
22
+ │ ├── Solution2.py
22
23
│ └── Solution2.js
23
24
├── 0003.Longest Substring Without Repeating Characters
24
25
│ ├── README.md
1274
1275
├── 5087.Letter Tile Possibilities
1275
1276
│ └── Solution.py
1276
1277
└── README.md
1277
- ```
1278
+ ```
You can’t perform that action at this time.
0 commit comments