Leecode<每日一题>错误的集合
题目链接:https://leetcode-cn.com/problems/set-mismatch/
思路:遍历标记即可
bool check[10010] = { false };
vector<int> findErrorNums(vector<int>& nums) {
vector<int> rt;
for (int i = 0; i < nums.size(); i++)
{
if (check[nums[i]]) rt.push_back(nums[i]);
else check[nums[i]] = true;
}
for (int i = 1; i <= nums.size(); i++)
{
if (!check[i])
{
rt.push_back(i);
break;
}
}
return rt;
}