法一:
class Solution {
public:
int missingNumber(vector& nums) {
int sum = 0;
int temp = 0;
for(int i = 0 ;i < nums.size();i++){
temp = temp + i;
sum =sum + nums[i];
}
return temp + nums.size() - sum;
}
};
法二:
class Solution {
public:
int missingNumber(vector& nums) {
sort(nums.begin(),nums.end());
for(int i = 0 ;i < nums.size();i++){
if(i != nums[i]){
return i;
}
}
return nums.size();
}
};