| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/mJackie/leetcode/master/code/lc191.java | [Back] [Original] |
package code;
/*
* 191. Number of 1 Bits
* 1
* Easy
* Bit Manipulation
*
* Tips
*/
public class lc191 {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int sum = 0;
int a = 1;
while(a!=0){
int b = n&a;
if(b!=0) sum += 1;
a
| Web Proxy Viewer | New URL | Original Page |