First Missing Positive
来源:互联网 发布:js中转换日期格式 编辑:程序博客网 时间:2024/05/29 04:59
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.
class Solution {public: int firstMissingPositive(int A[], int n){for (int i = 0; i < n; i++){while(A[i] != i + 1 && A[i] > 0 && A[i] <= n && A[i] != A[A[i] - 1])swap(A[i], A[A[i] - 1]);}for (int i = 0; i< n; i++)if(A[i] != i + 1)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
- Eclipse使用
- iOS 基础类解析 - NSString、NSMutableString
- //------------集合------------------------------------------
- 精简Linux文件路径
- 答一名总是半途而废的大二学生:如何坚持,坚持什么
- First Missing Positive
- Java基础知识总结(超级经典)
- 使用eclipse WTP内置的Web Services Explorer测试SOAP based Web Services
- android 格式化输入控制
- Introdution to 3D Game Programming With DirectX11 第12章 习题解答
- Introdution to 3D Game Programming With DirectX11 第13章 习题解答
- Introdution to 3D Game Programming With DirectX11 第14章 习题解答
- Introdution to 3D Game Programming With DirectX11 第15章 习题解答
- MIT differential equation---2