标签:int solution pre miss 异或 mis com size ble
方法一:求0到n的和,再减去nums数组的和,但是可能会超int
方法二:求0到n的异或值,在异或nums数组里的每个数字,不超int
class Solution {
public:
int missingNumber(vector<int>& nums) {
int x=0;
for(int i=1;i<=nums.size();i++)
{
x^=i;
}
for(int i=0;i<nums.size();i++)
{
x^=nums[i];
}
return x;
}
};
标签:int solution pre miss 异或 mis com size ble
原文地址:https://www.cnblogs.com/dacc123/p/12724627.html