题解 | 求最大连续bit数
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import sys n = bin(int(input()))[2:] s = 0 f = False res = 0 for _ in n: if _ == '1': f = True s += 1 else: f = False res = max(res,s) s = 0 if f: res = max(res,s) print(res)
bin 转二进制后用滑动窗口,滑动窗口需要注意尾部