File tree 3 files changed +43
-1
lines changed
3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } num
3
+ * @return {number }
4
+ */
5
+ const numberOfSteps = ( num ) => {
6
+ let count = 0 ;
7
+
8
+ while ( num > 0 ) {
9
+ count ++ ;
10
+ if ( num % 2 == 0 ) {
11
+ num /= 2 ;
12
+ } else {
13
+ num -- ;
14
+ }
15
+ }
16
+ return count ;
17
+ } ;
18
+
19
+ let x = null ;
20
+ x = numberOfSteps ( 14 ) ; // 6
21
+ x = numberOfSteps ( 8 ) ; // 6
22
+
23
+ console . log ( "Result" )
24
+ console . log ( x )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } num
3
+ * @return {number }
4
+ */
5
+ const numberOfSteps = ( num ) => {
6
+ let count = 0 ;
7
+
8
+ while ( num > 0 ) {
9
+ count ++ ;
10
+ if ( num % 2 == 0 ) {
11
+ num /= 2 ;
12
+ } else {
13
+ num -- ;
14
+ }
15
+ }
16
+ return count ;
17
+ } ;
Original file line number Diff line number Diff line change 72
72
- [ 997. Find the Town Judge] ( ./997/ )
73
73
- [ 1161. Maximum Level Sum of a Binary Tree] ( ./1161/ )
74
74
- [ 1187. Make Array Strictly Increasing] ( ./1187/ )
75
+ - [ 1342. Number of Steps to Reduce a Number to Zero] ( ./1342/ )
75
76
- [ 1365. How Many Numbers Are Smaller Than the Current Number] ( ./1365/ )
76
77
- [ 1480. Running Sum of 1d Array] ( ./1480/ )
77
78
- [ 1512. Number of Good Pairs] ( ./1512/ )
@@ -131,7 +132,7 @@ Batch create:
131
132
NOTE: JS IS HERE
132
133
-->
133
134
``` ssh
134
- chapter=832 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
135
+ chapter=1342 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
135
136
```
136
137
> then you can use ` x ` for quick debug.
137
138
You can’t perform that action at this time.
0 commit comments