problem
448. Find All Numbers Disappeared in an Array
solution:
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
vector<int> res;
for(int i=; i<nums.size(); i++)
{
int tmp = abs(nums[i]) - ;
nums[tmp] = nums[tmp]> ? -nums[tmp] : nums[tmp];
}
for(int i=; i<nums.size(); i++)
{
if(nums[i]>) res.push_back(i+);
}
return res;
}
};
参考
1. Leetcode_448. Find All Numbers Disappeared in an Array;
2. GrandYang;
完