二进制中1的个数

二进制中1的个数

http://www.nowcoder.com/questionTerminal/8ee967e43c2c4ec193b040ea7fbb10b8

public class Solution {
    public int NumberOf1(int n) {
        int count = 0;        
        while (n != 0) {
            // n < 0,则符号位为1
            if (n < 0) {
                ++ count;
            }        
            // 左移一位    
            n <<= 1;
        }
        return count;
    }
}
全部评论

相关推荐

06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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