输入一个 32 位整数,输出该数二进制表示中 1 的个数。
class Solution { public: int lowbit (int x) { return x & -x; } int NumberOf1(uint32_t x) { int ans = 0; while (x) { x -= lowbit(x); ans++; } return ans; } };
标签:return,二进制,lowbit,个数,int,ans From: https://www.cnblogs.com/leetothemoon/p/16980728.html