要求:有一个数重复/丢失
思路:
class Solution {
public:
vector<int> findErrorNums(vector<int>& nums) {
int n=nums.size();
vector<int> hash(n);
int lost,dup;
for(int i=0;i<n;++i){
hash[nums[i]-1]++;
}
for(int i=0;i<n;++i){
if(hash[i]==0)lost=i+1;
else if(hash[i]==2)dup=i+1;
}
return {dup,lost};
}
};