一、位1的个数
C++ Soution 1:
class Solution {
public:
int hammingWeight(uint32_t n)
{
int res = ;
for (int i = ; i < ; ++i)
{
res += (n & );
n = n >> ;
}
return res;
}
};
二、第k个排列
C++ Soution 1:
C++ Soution 1:
class Solution {
public:
int hammingWeight(uint32_t n)
{
int res = ;
for (int i = ; i < ; ++i)
{
res += (n & );
n = n >> ;
}
return res;
}
};
C++ Soution 1: