标签:amp find res nbsp ++ 题目 sbit blog data
class Solution { public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { if(data.size() == 0) return ; int res = 0; for(int i = 0;i < data.size();i++){ res ^= data[i]; } unsigned int index1 = FindFirstBitIs1(res); *num1 = *num2 = 0; for(int j = 0;j < data.size();++j){ if(isBit1(data[j],index1)) *num1 ^= data[j]; else *num2 ^= data[j]; } } unsigned int FindFirstBitIs1(int num){ int indexBit = 0; while(((num & 1) == 0) && (indexBit < 8*sizeof(int))){ num = num >> 1; ++indexBit; } return indexBit; } bool isBit1(int num,unsigned int indexBit){ num = num >> indexBit; return (num & 1); } };
标签:amp find res nbsp ++ 题目 sbit blog data
原文地址:http://www.cnblogs.com/xiuxiu55/p/6682258.html