做太多遍了,秒杀。
class Solution { public: int hammingWeight(uint32_t n) { int num = 0; for(;n; n &=(n-1), num++); return num; } };
时间: 2024-12-22 03:26:20
做太多遍了,秒杀。
class Solution { public: int hammingWeight(uint32_t n) { int num = 0; for(;n; n &=(n-1), num++); return num; } };