题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
#include <stdio.h> #include <string.h> int main() { int n; scanf("%d",&n); int k,pre=0,count=0,max=-1; while(n) { k=n%2; if(k==1) { if(pre==1) { count++; if(count>max) max=count; } else count=1; } pre=k; n/=2; } if(count>max) max=count; printf("%d\n",max); return 0; }