国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Leetcode 191. Number of 1 Bits

2019-11-10 22:57:31
字體:
來源:轉載
供稿:網友

Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).

For example, the 32-bit integer ’11’ has binary rePResentation 00000000000000000000000000001011, so the function should return 3.

s思路: 1. 移位就可以了!

class Solution {public: int hammingWeight(uint32_t n) { // int res=0; for(int i=0;i<32;i++){ if(n==0) break;//優化的不錯:判斷是否提前就等于0了,后面的操作就不必做了 res+=n&1; n>>=1; } return res; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖安县| 阳谷县| 南汇区| 仁怀市| 临城县| 扶沟县| 屏东市| 潜山县| 利辛县| 宁城县| 上杭县| 荥经县| 任丘市| 朝阳县| 布尔津县| 泰顺县| 岢岚县| 高尔夫| 西林县| 泗洪县| 陇川县| 上饶市| 昭苏县| 吉首市| 云林县| 登封市| 甘德县| 扬州市| 白朗县| 东乡族自治县| 新乡县| 涪陵区| 东乡族自治县| 宁远县| 庐江县| 海兴县| 长乐市| 墨竹工卡县| 桐梓县| 永德县| 张家川|