You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
public:intsingleNumber(vector<int>& nums) {
int num = 0;
for (int i = 0; i < nums.size(); i++) {
num = num ^ nums[i];
}
return num;
}
};
这题说起来不难,但是要求线性时间复杂度以及不能使用额外的空间,所以只能依赖于异或的特性:相同的数字异或等于0。