class Solution {
public:
int numberOfSteps(int num) {
int i=0;
while(num!=0){
if(num%2==0){
num=num/2;
i++;
}
else{
num=num-1;
i++;
}
}
return i;
}
};
将数字变成0的操作次数C++
![](https://img-home.csdnimg.cn/images/20240711042549.png)