当前位置:网站首页>Find all missing numbers in the array
Find all missing numbers in the array
2022-07-01 18:34:00 【Free dreamer】

We can mark the array directly , If there has been , We can turn it into a negative number , If it's negative , Then it means that this number often appears , Greater than 0 It means that there has been no .
step :
1. Traverse each number in the entire array , If not, multiply by -1, Here, the array subscript represents each number in the array
Be careful : because vector The subscript in is from 0 To n-1, The data range is from 1 To n So counting to the array requires -1 go in , Then there may be points appearing twice , Therefore, the number of current traversal should be changed into a positive number in advance ;
2. Traversal array , If there is an array, the following table is positive , It means there is no such thing as , We will i+1, Save to array .
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
for(auto c:nums){
c=abs(c);
if(nums[c-1]>0)nums[c-1]*=-1;
}
vector<int>res;
for(int i=0;i<nums.size();i++){
if(nums[i]>0)res.push_back(i+1);
}
return res;
}
};边栏推荐
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- Vue uses keep alive to cache page optimization projects
- JS how to convert a string with a delimiter into an n-dimensional array
- 12. Design of power divider for ads usage record
- Distributed task queue: Celery usage record
- What impact will multinational encryption regulation bring to the market in 2022
- Glidefast consulting was selected as the elite partner of servicenow in 2022
- An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
- Domestic spot silver should be understood
- Subnet division and summary
猜你喜欢

Bug of QQ browser article comment: the commentator is wrong

What impact will multinational encryption regulation bring to the market in 2022

Yolov5 practice: teach object detection by hand

主成分之综合竞争力案例分析

Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?

Static timing analysis (STA) in ic/fpga design

Penetration practice vulnhub range Tornado

PCL learning materials

Blue Bridge Cup real topic: the shortest circuit

MySQL connection tools
随机推荐
Flex layout
Blue Bridge Cup real problem: word analysis
Win10+vs2019 Community Edition compiling OpenSSL
Is Alipay wallet convenient to use?
Redis主从实现10秒检查与恢复
必看,时间序列分析
Computer network interview assault
PCL learning materials
Domestic spot silver should be understood
Nielseniq found that 60% of the re launched products had poor returns
APK签名流程介绍[通俗易懂]
Three dimensional anti-terrorism Simulation Drill deduction training system software
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
JS how to convert a string with a delimiter into an n-dimensional array
Detailed explanation of ArrayList expansion
The latest software scheme of the intelligent information management system of the armed police force
Set the style of QT property sheet control
主成分之综合竞争力案例分析
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
Data query language (DQL)