Skip to content

Commit 3a6f01e

Browse files
committed
1342. Number of Steps to Reduce a Number to Zero
1 parent 45dafe4 commit 3a6f01e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
3+
class Solution {
4+
public:
5+
int numberOfSteps(int num) {
6+
int count=0;
7+
8+
while(num != 0){
9+
if(num%2 != 0){
10+
num = num-1;
11+
}else{
12+
num = num/2;;
13+
}
14+
count++;
15+
}
16+
return count;
17+
}
18+
};

0 commit comments

Comments
 (0)