题解 | #求最大连续bit数#
求最大连续bit数
http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = Integer.valueOf(scan.nextLine().trim());
int ans = 0;
int acc = 0;
int sign = 0;
while (num != 0) {
if (num % 2 == 0) {
if (sign == 1) {
sign = 0;
ans = Math.max(ans, acc);
acc = 0;
}
} else {
if (sign == 0) {
sign = 1;
}
acc++;
}
num /= 2;
}
ans = Math.max(ans, acc);
System.out.println(ans);
}
}