add: 220526 [cpp]

This commit is contained in:
Eat-Swap 2022-05-26 20:22:59 +08:00
parent b01dc3baf5
commit 0e8f9b9065
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 13 additions and 0 deletions

13
cpp/2205/220526.cpp Normal file
View File

@ -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);
}
};