题解 | #求最大连续bit数#

求最大连续bit数

http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int num = sc.nextInt();
            String str = "";
            
            while(num != 0){
                if(num%2!=0){
                   str = 1 + str;
                }else{
                   str = 0 + str;
                }
                num = num >>>1;
            }
            //System.out.println(str+"============");
            String[] s = str.split("0");
            int max = 0;
            for(int i=0;i<s.length;i++){
                if(s[i].length()>max){
                    max = s[i].length();
                }
            }
             System.out.println(max);
        } 
    }
}
全部评论

相关推荐

06-27 15:29
门头沟学院 Java
点赞 评论 收藏
分享
机械打工仔:第一位颇有孟德之志
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
xdm怎么说&nbsp;要被拷打了&nbsp;担心是KPI
丹田:面就完了,就当日薪四位数的大佬免费给给你面试。
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务