Skip to content

Commit dfed104

Browse files
committed
Runtime: 67 ms (Top 46.85%) | Memory: 14.2 MB (Top 25.08%)
1 parent de467d5 commit dfed104

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
# Runtime: 67 ms (Top 46.85%) | Memory: 14.2 MB (Top 25.08%)
2+
13
class Solution:
2-
def addStrings(self, num1: str, num2: str) -> str:
3-
num1 = list(num1)
4-
num2 = list(num2)
4+
def addStrings(self, num1: str, num2: str) -> str:
5+
num1 = list(num1)
6+
num2 = list(num2)
57

6-
ans = ''
7-
carry = 0
8-
while num1 and num2:
9-
p = int(num1.pop()) + int(num2.pop()) + carry
10-
carry = p//10
11-
ans = str(p%10) + ans
8+
ans = ''
9+
carry = 0
10+
while num1 and num2:
11+
p = int(num1.pop()) + int(num2.pop()) + carry
12+
carry = p//10
13+
ans = str(p%10) + ans
1214

13-
while num1:
14-
p = int(num1.pop()) + carry
15-
carry = p//10
16-
ans = str(p%10) + ans
15+
while num1:
16+
p = int(num1.pop()) + carry
17+
carry = p//10
18+
ans = str(p%10) + ans
1719

18-
while num2:
19-
p = int(num2.pop()) + carry
20-
carry = p//10
21-
ans = str(p%10) + ans
20+
while num2:
21+
p = int(num2.pop()) + carry
22+
carry = p//10
23+
ans = str(p%10) + ans
2224

23-
if carry: ans = str(carry) + ans
24-
return ans
25+
if carry: ans = str(carry) + ans
26+
return ans

0 commit comments

Comments
 (0)