题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { //testCompletePack(); testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { String toBinaryString = Integer.toBinaryString(Integer.parseInt(str)); char[] chars = toBinaryString.toCharArray(); int count = 0; int max = 0; for (char aChar : chars) { if (aChar == '1') count++; if (max < count) { max = count; } if (aChar == '0')count = 0; } System.out.println(max); } } }