当前位置:网站首页>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;
}
};
边栏推荐
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- t10_ Adapting to Market Participantsand Conditions
- Penetration practice vulnhub range Tornado
- Penetration practice vulnhub range Keyring
- Software construction scheme of smart factory collaborative management and control application system
- 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
- Develop those things: add playback address authentication to easycvr platform
- (6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
- Penetration practice vulnhub range Nemesis
- [CF559E]Gerald and Path
猜你喜欢
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Flex layout
Record 3 - the state machine realizes key control and measures the number of external pulses
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Static timing analysis (STA) in ic/fpga design
Distributed task queue: Celery usage record
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
Localization through custom services in the shuttle application
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
随机推荐
Win10+vs2019 Community Edition compiling OpenSSL
Draw drawing process of UI drawing process
Small exercise -- subnet division and summary
PMP daily three questions (February 15, 2022)
必看,时间序列分析
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
MySQL + JSON = King fried
Terms related to K line
主成分计算权重
[PHP foundation] realize the connection between PHP and SQL database
Static timing analysis (STA) in ic/fpga design
Fix the black screen caused by iPhone system failure
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion
Computer network interview assault
540. Single element in ordered array
Is online stock account opening safe? Is it reliable?
Length of learning and changing
Can hero sports go public against the wind?
Calculation of intersection of two line segments