1342.cpp (257B)
1 class Solution { 2 public: 3 int numberOfSteps(int num) { 4 int res = 0; 5 while (num) { 6 res++; 7 if (num % 2 == 0) 8 num /= 2; 9 else 10 num--; 11 } 12 return res; 13 } 14 };