-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbinaryGap.py
More file actions
37 lines (30 loc) · 712 Bytes
/
binaryGap.py
File metadata and controls
37 lines (30 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
decimal = input("decimal: ")
binary = bin(int(decimal))
binary = binary[2:]
bin1 = bin(1)
bin0 = bin(0)
# print(bin0, bin1)
firstOne = -1
count = 0
for i in range(0, len(binary)):
print("i first: ", i)
temp = 0
if binary[i] == '1':
flag = False
while i <= len(binary)-2 :
if binary[i+1] == '1':
flag = True
break
else:
temp += 1
i += 1
if not flag:
break
else:
if temp > count:
count = temp
print("i last: ", i)
print("temp: ", temp)
print("count: ", count)
print(binary) #, binary[0], binary[1], len(binary))
# 10100