博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Number of 1 Bits
阅读量:4650 次
发布时间:2019-06-09

本文共 547 字,大约阅读时间需要 1 分钟。

class Solution {public:    int hammingWeight(uint32_t n) {        string aaa = toBinary(n);        in count = 0;        for(int i = 0; i < sizeof(aaa); i++)    {            if(aaa[i] == "1")                count++;        }        return count;    }        string toBinary(unsigned int val)    {        string aaa = "";        for(int i = 16; i >= 0; i--)    {            if(val & (1 << i))                aaa += "1";            else                aaa += "0";        }        return aaa;    }};

 

转载于:https://www.cnblogs.com/QingHuan/p/5054553.html

你可能感兴趣的文章
P4878 道路修建-美国
查看>>
dp练习
查看>>
vim
查看>>
maze_travel的隐私声明
查看>>
对正则表达式又重新学了一遍,笔记方便以后查阅
查看>>
UIKit应用 - Swift 版本: 3.让UITableViewCell的背景色渐变
查看>>
Java反射
查看>>
building tool
查看>>
JS中for循环输出三角形
查看>>
字节对齐2
查看>>
与Win8之磁盘活动时间100%斗争心得
查看>>
Matrix: android 中的Matrix (android.graphics.Matrix) (转)
查看>>
Android中处理崩溃异常
查看>>
Day7—socket进阶
查看>>
只读数据文件损坏恢复
查看>>
转过来的,可以看下
查看>>
windows搭建SVN服务MD版
查看>>
HashMap的工作原理
查看>>
一碗饭
查看>>
floyd求最小环 模板
查看>>