Skip to content

Commit a1c7b43

Browse files
committed
Time: 5 ms (100%), Space: 18 MB (100%) - LeetHub
1 parent 332226c commit a1c7b43

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# time complexity: O(n)
2+
# space complexity: O(n)
3+
class Solution:
4+
def minimumFlips(self, n: int) -> int:
5+
original = bin(n)[2:]
6+
reverse = original[::-1]
7+
count = 0
8+
for i in range(len(original)):
9+
if original[i] != reverse[i]:
10+
count += 1
11+
return count
12+
13+
14+
n = 7
15+
print(Solution().minimumFlips(n))
16+
n = 10
17+
print(Solution().minimumFlips(n))

0 commit comments

Comments
 (0)