当前位置:网站首页>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;
}
};边栏推荐
- Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion
- Draw drawing process of UI drawing process
- Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
- [CF1476F]Lanterns
- Calculation of intersection of two line segments
- Set the style of QT property sheet control
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
- The new server is packaged with the source code of H5 mall with an operation level value of several thousand
- Is Huishang futures a regular futures platform? Is it safe to open an account in Huishang futures?
- Penetration practice vulnhub range Tornado
猜你喜欢

Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion

Review Net 20th anniversary development and 51aspx growth

Length of learning and changing

Yuancosmos game farmersworld farmers world - core content of the second conference in China!

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

Definition of rotation axis in mujoco

Bernoulli distribution (a discrete distribution)

The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
![Htt [ripro network disk link detection plug-in] currently supports four common network disks](/img/e4/c06b94243cdbe391b8b2124ff30789.jpg)
Htt [ripro network disk link detection plug-in] currently supports four common network disks

Mujoco's biped robot Darwin model
随机推荐
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
What are the legal risks of NFT brought by stars such as curry and O'Neill?
MFC obtains local IP (used more in network communication)
PTA year of birth
golang中的select详解
Is the fund of futures account safe? How to open an account?
Thinkphp6 - CMS multi wechat management system source code
Nielseniq found that 60% of the re launched products had poor returns
ZABBIX alarm execute remote command
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
Step size of ode45 and reltol abstol
目前炒期货在哪里开户最正规安全?怎么期货开户?
SCP -i private key usage
The latest software scheme of the intelligent information management system of the armed police force
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
Function, condition, regular expression
Penetration practice vulnhub range Tornado
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Fix the black screen caused by iPhone system failure
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source