20170611-leetcode-041-First Missing Positive
来源:互联网 发布:瑞士胡椒盐包带淘宝 编辑:程序博客网 时间:2024/06/05 08:43
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
阅读全文
0 0
- 20170611-leetcode-041-First Missing Positive
- LeetCode 041 First Missing Positive
- leetcode 041 First Missing Positive
- LeetCode 041 First Missing Positive
- LeetCode: First Missing Positive
- LeetCode First Missing Positive
- LeetCode: First Missing Positive
- [Leetcode] First Missing Positive
- [LeetCode] First Missing Positive
- [Leetcode] First Missing Positive
- leetcode First Missing Positive
- LeetCode First Missing Positive
- [leetcode] first missing positive
- LeetCode: First Missing Positive
- [LeetCode]First Missing Positive
- LeetCode-First Missing Positive
- [leetcode] First Missing Positive
- [LeetCode] First Missing Positive
- JAVA源码解析(8)-java.beans.PersistenceDelegate
- 云片网短信的接入
- 基于FPGA和USB的高速数据采集及显示系统
- iOS 11 拖拽支持(drag-drop)
- System类中的arraycopy方法
- 20170611-leetcode-041-First Missing Positive
- shiro小结
- java获取客服端信息(系统,浏览器等)
- 浏览器历史记录
- 微信公众平台开发(71)OAuth2.0网页授权---流程
- 全选反选全不选
- 【js】小数精度(去位取整和四舍五入)
- TGT + TAPE
- socket.io 中文文档