题意
n个数, 统计1-n中未出现的数
方法
遍历和标记
代码
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
sort(nums.begin(), nums.end());
int n = nums.size();
vector<int> ans;
vector<int> num(100024);
for (int i = 0; i <= n; i++) {
num[i] = 0;
}
for (int i = 0; i < n; i++) {
num[nums[i]] = 1;
}
for (int i = 1; i <= n; i++) {
if (num[i] == 0) ans.push_back(i);
}
return ans;
}
};
标签:nums,int,LeetCode448,Disappeared,vector,Numbers,Array
From: https://www.cnblogs.com/Figure_at_a_Window/p/16708938.html