448FindAllNumbersDisappearedInAnArray
来源:互联网 发布:linux菜鸟私房菜 编辑:程序博客网 时间:2024/05/16 15:22
448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements of [1, n] inclusive that do not appear in this array.
Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
Example:
Input:
[4,3,2,7,8,2,3,1]
Output:
[5,6]
vector<int> findDisappearedNumbers(vector<int>& nums) { int size=nums.size(); set<int> numsSet{}; numsSet.insert(nums.begin(),nums.end()); nums.erase(nums.begin(),nums.end()); for(int i=1;i<=size;++i) { if(numsSet.count(i)==0) nums.push_back(i); } for (auto num:nums) { cout<<num<<endl; } return nums; }
vector<int> findDisappearedNumbers(vector<int>& nums) { int size=nums.size(); vector<int> result{}; vector<int > vector1{}; for(int i=1;i<=size;++i){ result.push_back(i); } for(auto num:nums) { result[num-1]=-1; } for(int i=0;i<size;++i) { if(result[i]!=-1) vector1.push_back(i+1); } return vector1; }
阅读全文
0 0
- 448FindAllNumbersDisappearedInAnArray
- leetcode ---448---FindAllNumbersDisappearedinanArray
- FindAllNumbersDisappearedInAnArray
- CodeForces 448
- NYOJ 448
- ocp-448
- nyoj 448
- leetcode 448
- LeetCode--448
- UVa 448
- SRM 448 div1(practice)
- codeforces-448A-Rewards
- Codeforces 448A Rewards
- 448C. Painting Fence
- codeforces 448CPainting Fence
- Codeforces 448E Divisors
- 448 寻找最大数
- CodeForces 448-A. Rewards
- leetcode解题方案--061--RotateList
- python学习笔记 第七章(二)
- IA-32 Intel手册学习笔记(三)任务切换
- sdnu-并查集-weeklyexam ——I
- 告别session jwt使用初尝试
- 448FindAllNumbersDisappearedInAnArray
- 计算机网络中,16位校验和的实现
- ACM 比赛如何正确开局、队员如何分工、如何把状态调整到最佳?
- zk框架
- 10.字符串倒置
- jQuery教程 5 效果
- C# Parallel.Invoke 实现
- mybatis学习(三)SQL语句映射文件 增删改查、参数、缓存
- Cuda安装步骤记录(超详尽)