当前位置:网站首页>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;
}
};边栏推荐
- 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
- The latest software scheme of the intelligent information management system of the armed police force
- Convert the robot's URDF file to mujoco model
- Small exercise -- subnet division and summary
- Thinkphp6 - CMS multi wechat management system source code
- Flex layout
- 期货账户的资金安全吗?怎么开户?
- Redis主从实现10秒检查与恢复
- Common design parameters of solid rocket motor
- Fix the black screen caused by iPhone system failure
猜你喜欢

Flex layout

Classpath classpath

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

Data query language (DQL)

Yolov5 practice: teach object detection by hand

Depth first search - DFS (burst search)

Samba basic usage

A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database

12. Design of power divider for ads usage record

Work and leisure suggestions of old programmers
随机推荐
SCP -i private key usage
Flex layout
Mysql database design
Happy new year | 202112 monthly summary
Blue Bridge Cup real topic: the shortest circuit
Talk about the favorite tools used by project managers
What are the legal risks of NFT brought by stars such as curry and O'Neill?
The method of real-time tracking the current price of London Silver
On the language internationalization of Yongzhong Office
C operator overloads the query table
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
[acnoi2022] color ball
Sanfeng cloud 0215 I often use
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
Calculation of intersection of two line segments
Can hero sports go public against the wind?
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
主成分之综合竞争力案例分析
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #