Skip to content

Commit fd0fae7

Browse files
authored
Create 3827. Count Monobit Integers.py
1 parent 863d6f7 commit fd0fae7

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def countMonobit(self, n: int) -> int:
3+
def is_monobit(num):
4+
binary = bin(num)[2:]
5+
base = binary[0]
6+
for b in binary:
7+
if b != base:
8+
return False
9+
return True
10+
11+
ans = 0
12+
for i in range(n+1):
13+
ans += is_monobit(i)
14+
return ans
15+
16+
17+

0 commit comments

Comments
 (0)