Leetcode 338 Counting Bits

来源:互联网 发布:淘宝运营助理工资 编辑:程序博客网 时间:2024/06/17 02:21

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;    }};
原创粉丝点击