您的位置:首页 > 其它

Leetcode 338 Counting Bits

2017-07-02 16:10 351 查看

Leetcode 338 Counting Bits

#include <vector>
#include <intrin.h>//__popcnt
#include<nmmintrin.h>
using namespace std;

class Solution {
public:
vector<int> countBits(int num) {
vector<int> bitsNum;
for (int i = 0; i <= num; i++){
int count = 0;
/*while (i){
i = i &(i - 1);
count++;
}*/
//__builtin_popcount(i);gcc的内建函数,计算一个32位无符号整数有多少位为1
//count = __popcnt(i);//vs情况下,MSVC
count = _mm_popcnt_u32(i);
bitsNum.push_back(count);// SSE4 Streaming SIMD Extensions 4, intel处理器继承指令集的一个版本
}
return bitsNum;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode