【leetcode】448. Find All Numbers Disappeared in an Array

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;

上一篇:linux图形化客户端


下一篇:【PPT详解】曹欢欢:今日头条算法原理