20170611-leetcode-041-First Missing Positive
2017-06-12 11:25
381 查看
1.Description
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.
解读
给定一个无序的数组,找到第一个缺失的正整数,要求时间为 O ( n )
比如:【1,2,0】,返回3
【900,-1】,返回1
2.Solution
思路:找到最大值,然后遍历一下class Solution(object): def firstMissingPositive(self, nums): if not nums: return 1 maxNum = max(nums) for i in range(1, maxNum + 2): if i not in nums: return i
相关文章推荐
- Java for LeetCode 041 First Missing Positive
- [LeetCode]题解(python):041-First Missing Positive
- leetcode_c++:First Missing Positive(041)
- LeetCode 041 First Missing Positive
- LeetCode 041 First Missing Positive
- leetcode 041 —— First Missing Positive
- leetcode解题方案--041--First Missing Positive
- leetcode 041 First Missing Positive
- [LeetCode]041-First Missing Positive Integer
- leetcode-41 First Missing Positive
- leetcode--First Missing Positive
- LeetCode | First Missing Positive
- LeetCode_First Missing Positive
- leetcode-First Missing Positive
- [LeetCode]First Missing Positive(!!!)
- LeetCode(41)First Missing Positive
- LeetCode: First Missing Positive 解题报告
- LeetCode刷题笔录First Missing Positive
- LeetCode 43: First Missing Positive
- LeetCode : First Missing Positive [java]