We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b4ed9f commit 8fe08f5Copy full SHA for 8fe08f5
my-submissions/e1342 v1 simulation.py
@@ -0,0 +1,7 @@
1
+class Solution:
2
+ def numberOfSteps(self, num: int) -> int:
3
+ if num == 0 :
4
+ return 0
5
+ if num % 2 :
6
+ return 1 + self.numberOfSteps(num - 1)
7
+ return 1 + self.numberOfSteps(num // 2)
my-submissions/e1342 v2 binary.py
+ bin_str = bin(num)[3:]
+ ones = bin_str.count('1')
+ return 1 + 2 * ones + len(bin_str) - ones
0 commit comments