File tree 1 file changed +21
-19
lines changed
scripts/algorithms/A/Add Strings
1 file changed +21
-19
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 67 ms (Top 46.85%) | Memory: 14.2 MB (Top 25.08%)
2
+
1
3
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 )
5
7
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
12
14
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
17
19
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
22
24
23
- if carry : ans = str (carry ) + ans
24
- return ans
25
+ if carry : ans = str (carry ) + ans
26
+ return ans
You can’t perform that action at this time.
0 commit comments