First Missing Positive
来源:互联网 发布:alexnet网络详解 编辑:程序博客网 时间:2024/05/22 08:13
Given an unsorted integer array, find the first missing positive integer.
For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.
Your algorithm should run in O(n) time and uses constant space
思路参考了http://blog.csdn.net/pickless/article/details/9234301
大多数人也采用的是让原数组多带些信息(采用负号)来实现hash。
int firstMissingPositive(int A[], int n){ int i; for(i=0; i<n; ++i) { if(A[i]<=0) A[i] = n+2; } for(i=0; i<n; ++i) { if(abs(A[i])<=n) { int cur = abs(A[i])-1; A[cur] = -abs(A[cur]); } } for(i=0; i<n; ++i) if(A[i] > 0) return i+1; return n+1;}
0 0
- LeetCode: First Missing Positive
- LeetCode First Missing Positive
- LeetCode: First Missing Positive
- [Leetcode] First Missing Positive
- leetcode12: First Missing Positive
- First Missing Positive
- [LeetCode] First Missing Positive
- [Leetcode] First Missing Positive
- leetcode First Missing Positive
- LeetCode First Missing Positive
- [leetcode] first missing positive
- First Missing Positive
- LeetCode: First Missing Positive
- First Missing Positive
- First Missing Positive
- [LeetCode]First Missing Positive
- First Missing Positive
- First Missing Positive
- 微信公众号的类型和功能
- 如何将Mac OS X10.9下的Python2.7升级到最新的Python3.3
- gcc常用命令
- 关于linux/UNIX为什么比windows安全的技术解释
- having的用法
- First Missing Positive
- [LeetCode] Search in Rotated Sorted Array
- linux测试题整理 (2)
- 网络编程
- ERROR: C:\snort\etc\snort.conf(489)=>unable to open addreess file c:\snort\etc\C:\snort\rules\white
- 招聘软件开发工程师/开发实习生
- js通用数据检测类(1)
- <java——异常、package>
- VCF格式详解