코딩 문제
[LeetCode] 1342 Number of Steps to Reduce a Number to Zero, C
Zach Choi
2022. 12. 28. 08:54
728x90
반응형
Solution
- Simple sequential calculation
Other Solution
- can use binary operation
int numberOfSteps(int num) {
int step = 0;
while (num != 0)
{
if (num % 2 == 0)
{
num = num / 2;
}
else
{
num -= 1;
}
++step;
}
return step;
}
728x90
반응형