class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
if(nums.empty()) return nums;
int size = nums.size();
for(int i=0;i<size; ++i){
while(nums[i]!=i+1 && nums[i]!=nums[nums[i]-1]){
swap(nums,i,nums[i]-1);
}
}
vector<int> res;
for(int i=0;i<size;++i){
if(nums[i] != i+1)
res.push_back(i+1);
}
return res;
}
void swap(vector<int>& nums,int i,int j){
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
};
448. 找到所有数组中消失的数字/C++
最新推荐文章于 2023-11-22 21:38:33 发布