irst-missing-positive
来源:互联网 发布:全球电视直播软件apk 编辑:程序博客网 时间:2024/05/21 18:44
题目:
Given an unsorted integer array, find the first missing positive integer.
For example,
Given[1,2,0]return3,
and[3,4,-1,1]return2.
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] > 0 && A[i] <= n && A[A[i] - 1] != A[i]) 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
- irst-missing-positive
- 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
- Activity的启动模式
- ActiveMQ笔记——技术点汇总
- 最全Pycharm教程(18)——Pycharm编辑器功能之代码拼写提示
- LeetCode
- 设计模式 ----- 策略模式
- irst-missing-positive
- 制作java程序安装包
- 委托类型作为方法参数的传递
- 防火墙
- 编程名词积累解析
- 人脸认证-ROC曲线绘制计算AUC和ACC
- Collections和Collection的区别
- discovery studio v2.5免费版下载 附安装教程
- 数据结构——线性表——顺序表