当前位置:网站首页>LeetCode 41. Missing first positive number
LeetCode 41. Missing first positive number
2022-04-22 19:10:00 【HumbleFool】
41. First positive number missing

In situ Hash
class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
int n = nums.size();
for(int i = 0; i < n; i ++)
{
// In situ hash, Will be nums[i] Put it in (nums[i] - 1) position
// Constantly changing positions , final nums[i] And i + 1 Unequal positions do not exist
while(nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] != nums[i])
swap(nums[nums[i] - 1], nums[i]);
}
for(int i = 0; i < n; i ++)
if(nums[i] != i + 1)
return i + 1;
return n + 1;
}
};
版权声明
本文为[HumbleFool]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221905153812.html
边栏推荐
- Can deleted photos be restored? 3 tips to restore deleted photos
- linux系统下redis相关问题
- 被删除的相片能恢复吗?3个技巧恢复被删除的相片
- 2020-12-15 rocksdb研究
- [TCP] TCP three handshakes and four waves
- Welcome page display
- 爱可可AI前沿推介 (4.22)
- C -- database connection statement
- C # joint programming with Halcon
- Issues related to redis in Linux system
猜你喜欢

leetcode:642.设计搜索自动补全系统

Network security -- the use of burp suite packet capture tool

【面试普通人VS高手系列】请说一下网络四元组

Redis缓存之String的滥用

LeetCode 41. 缺失的第一个正数

Vs 2022 installing VLD memory leak detection tool

微服务负载均衡器Ribbon介绍

高德Flutter官方组件amap_flutter_map在地图上画圆

Cvpr2022 𞓜 collaborative dual stream visual language pre training model for cross modal retrieval

关于字符串常量池,intern方法的理解
随机推荐
Fingerprint identification record
关于字符串常量池,intern方法的理解
1372:小明的账单
[appium stepping on the pit] could not proxy command to the remote server Original error: timeout of 240000ms exceeded
What happens when you run the NPM install command?
Error c4996 'fopen': this function or variable may be unsafe Consider using fopen_ s instead. To disabl
高速野蛮生长的单片机嵌入式行业,各个岗位的需求也随之增大
项目实训- 基于unity的2D多人乱斗闯关游戏设计与开发(五、利用AudioMixer控制音量大小)
原来,这才是开发者打开世界读书日的正确姿势
配置拦截器不拦截Swagger
[early spring 2022] [leetcode] 695 Maximum area of the island
项目实训- 基于unity的2D多人乱斗闯关游戏设计与开发(三、Unity PlasticSCM多人协同)
Configure interceptor not to intercept swagger
The beautiful and comfortable kn95 mask has strong protection ability
LC刷题第四天
Line by line interpretation of redet code
【最佳实践】巡检项:内容分发网络(CDN)开启URL鉴权
Alibaba微服务组件Sentinel介绍
MCU infrared module knowledge sharing theory is the basis of practical combat in the future
How to build the campus running platform?