题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
java提交,耗费时间和内存均超过80%多的提交,个人觉得这个方法效率最高
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
int max = 0;
int tmp = 0;
while(num >=1){
if(num%2==1){
tmp++;
max = Math.max(max,tmp);
}else{
tmp =0;
}
num = num >>>1;
}
System.out.println(max);
}
}
