File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } num1
3
+ * @param {string } num2
4
+ * @return {string }
5
+ */
6
+ var addStrings = function ( num1 , num2 ) {
7
+ const ans = [ ]
8
+ let remainder = 0
9
+ let i = num1 . length - 1
10
+ let j = num2 . length - 1
11
+ while ( remainder || i >= 0 || j >= 0 ) {
12
+ let sum = ( num1 [ i ] == null ? 0 : + num1 [ i ] ) + ( num2 [ j ] == null ? 0 : + num2 [ j ] ) + remainder
13
+ ans . push ( sum % 10 )
14
+ remainder = Math . floor ( sum / 10 )
15
+ j --
16
+ i --
17
+ }
18
+ return ans . reverse ( ) . join ( '' )
19
+ } ;
20
+
21
+ console . log ( addStrings ( '0' , '0' ) )
Original file line number Diff line number Diff line change 135
135
- [ 398 Random Pick Index] ( ./398 )
136
136
- [ 347 Top K Frequent Elements] ( ./347 )
137
137
- [ 414 Third Maximum Number] ( ./414 )
138
+ - [ 415 Add Strings] ( ./415 )
138
139
- [ 442 Find All Duplicates in an Array] ( ./442 )
139
140
- [ 448 Find All Numbers Disappeared in an Array] ( ./448 )
140
141
- [ 495 Teemo Attacking] ( ./495 )
You can’t perform that action at this time.
0 commit comments