数组中只出现一次的两个数字

#include
#include
using namespace std;

vector findNumsAppearOnce(vector& nums) {
	int eO = 0, eOhasOne = 0;
	for (int curNum : nums) {
		eO ^= curNum;
	}
	int rightOne = eO & (~eO + 1);
	for (int cur : nums) {
		if ((cur & rightOne) == 0) {
			eOhasOne ^= cur;
		}
	}
	vectorb;
	b.push_back(eOhasOne);
	b.push_back((eO ^ eOhasOne));
	return b;
}

 

你可能感兴趣的:(数据结构与算法)