题解 | #求最大连续bit数#速度有点慢
求最大连续bit数
http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
while True:
try:
n = int(input())
bin_str = bin(n)
max_len = 0
for i in range(len(bin_str)):
if bin_str[i] != '1':
continue
for j in range(i, len(bin_str)):
if bin_str[i: j + 1].count('1') == len(bin_str[i: j + 1]):
if len(bin_str[i: j + 1]) > max_len:
max_len = len(bin_str[i: j + 1])
print(max_len)
except:
break