当前位置:网站首页>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;
}
};边栏推荐
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
- Htt [ripro network disk link detection plug-in] currently supports four common network disks
- The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
- What is web application security testing technology?
- Computer network interview assault
- LeetCode 148. Sort linked list
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
- Redis master-slave realizes 10 second check and recovery
猜你喜欢

Record 3 - the state machine realizes key control and measures the number of external pulses

t10_ Adapting to Market Participantsand Conditions

Length of learning and changing

transform. Forward and vector3 Differences in the use of forward

The method of real-time tracking the current price of London Silver

Set the style of QT property sheet control

What are the legal risks of NFT brought by stars such as curry and O'Neill?
![[PHP foundation] realize the connection between PHP and SQL database](/img/eb/c8953eddfe3b19b0adb5529957d275.jpg)
[PHP foundation] realize the connection between PHP and SQL database

Penetration practice vulnhub range Keyring

Check log4j problems using stain analysis
随机推荐
D. Yet Another Minimization Problem
Oracle TRUNC function processing date format
主成分之综合竞争力案例分析
How to learn automated testing?
Computer network interview assault
Step size of ode45 and reltol abstol
Domestic spot silver should be understood
Apk signature process introduction [easy to understand]
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Terms related to K line
Localization through custom services in the shuttle application
Set the style of QT property sheet control
[CF559E]Gerald and Path
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
February 16, 2022 Daily: graph neural network self training method under distribution and migration
MySQL + JSON = King fried
Irradiance, Joule energy, exercise habits