Leetcode 448 Solution
This article provides solution to leetcode question 448 (find-all-numbers-disappeared-in-an-array)
Access this page by simply typing in "lcs 448" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array
Solution
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
for (int i = 0; i < nums.size(); i++)
{
int num = nums[i];
nums[abs(num) - 1] = -abs(nums[abs(num) - 1]);
}
vector<int> res;
for (int i = 0; i < nums.size(); i++)
{
int num = nums[i];
if (num > 0)
res.push_back(i + 1);
}
return res;
}
};