Finding consecutive bit string of 1 or 0

前端 未结 10 696
刺人心
刺人心 2020-11-29 05:27

How to find the length of the longest consecutive bit string(either 1 or 0)?

00000000 11110000 00000000 00000000 -> If it is 0 then length will be 20

11111

10条回答
  •  盖世英雄少女心
    2020-11-29 06:12

    It may help you.... First convert your binary number to String say bits. It will give you max number of consecutive 1's (in java)

    String[] split = bits.split("0");
    Arrays.sort(split);
    int maxLength = split[split.length - 1].length();
    

提交回复
热议问题