zoukankan      html  css  js  c++  java
  • 【leetcode】【191】Number of 1 Bits

    #include<iostream>
    #include<stdint.h>
    using namespace std;
    
    class Solution {
    public:
    	int hammingWeight(uint32_t n) {
    		int count = 0;
    		while (n){
    			n &= (n - 1);//见http://blog.csdn.net/ruan875417/article/details/43018069
    			++count;
    		}
    		return count;
    	}
    };
    
    int main(){
    	Solution solution;
    	cout << solution.hammingWeight(11) << endl;
    
    	system("pause");
    	return 0;
    }

  • 相关阅读:
    bzoj 4610 Ceiling Functi
    uva 01350
    uva 12075
    uva 01393
    uva 11038
    CF 496E
    CF 496D
    poj 3167
    hdu 4622
    spoj 7258
  • 原文地址:https://www.cnblogs.com/ruan875417/p/4495556.html
Copyright © 2011-2022 走看看