Skip to content

Commit 6222698

Browse files
authored
Create 1342-number-of-steps-to-reduce-a-number-to-zero.js
1 parent b1edcb0 commit 6222698

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number} num
3+
* @return {number}
4+
*/
5+
const numberOfSteps = function(num) {
6+
let res = 0
7+
while(num !== 0) {
8+
if(num % 2 === 0) {
9+
num /= 2
10+
} else num--
11+
res++
12+
}
13+
14+
return res
15+
};

0 commit comments

Comments
 (0)