add: 220526 [cpp]
This commit is contained in:
parent
b01dc3baf5
commit
0e8f9b9065
|
|
@ -0,0 +1,13 @@
|
|||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* 191. Number of 1 Bits
|
||||
* Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int hammingWeight(uint32_t n) {
|
||||
return __builtin_popcount(n);
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue