面试经典150题 P191 位1的个数 Created:2025-11-25 13:31:13Updated:2025-11-25 13:31:13algorithmalgorithm, leetcode面试经典150题, 位操作字数 59阅读 访客 时间轴 时间轴2025-11-25init __builtin_popcount 题目:P191 位1的个数https://leetcode.cn/problems/number-of-1-bits/description/?envType=study-plan-v2&envId=top-interview-150可以直接使用内置函数__builtin_popcount1234567class Solution { public: int hammingWeight(int n) { return __builtin_popcount(n); }};