1342. 将数字变成 0 的操作次数

执行用时:0 ms, 在所有 Java 提交中击败了100.00% 的用户
内存消耗:38.1 MB, 在所有 Java 提交中击败了5.31% 的用户
通过测试用例:204 / 204

Happy lunar new year!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int numberOfSteps(int num) {
int count = 0;
while (num > 0) {
if (num % 2 == 0) {
num /= 2;
} else {
num--;
}
count++;
}
return count;
}
}

1342. 将数字变成 0 的操作次数
https://pisces34.github.io/2022/01/31/leetcode/1342/
发布于
2022年1月31日
许可协议