https://leetcode.com/problems/first-missing-positive/
来源:互联网 发布:linux date 格式化 编辑:程序博客网 时间:2024/06/05 10:26
https://leetcode.com/problems/first-missing-positive/
题目很好懂
我的做法是
1.删除所有非正数
2.去重
3.排序
4.看下标和值不相差1 如果都相同 那就少list里的下一个
一定有更好的方法
class Solution: # @param {integer[]} nums # @return {integer} def firstMissingPositive(self, nums): listi=[] for i in nums: if i>0: listi.append(i) listi = list(set(listi))#去重的函数 !!!!!! listi.sort()#排序 if len(listi)==0: return 1 else: for i in range(len(listi)): if listi[i]!=i+1: return i+1 break else: if i==len(listi)-1: return len(listi)+1
0 0
- https://leetcode.com/problems/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
- LeetCode - First Missing Positive
- LeetCode | First Missing Positive
- Leetcode: First Missing Positive
- 网上商城—管理员修改商品
- 机房重构-----判断输入框是否为空,一键清除输入框
- 【JAVA学习】7.javabean
- The React.js Way: Getting Started Tutorial
- HDU ACM 2153仙人球的残影
- https://leetcode.com/problems/first-missing-positive/
- ios中NSString与NSDate互转
- Android中Fragment的两种使用方法
- HDU-2079-母函数
- open函数读文件最后乱码
- Spring Boot开发之流水无情(二)
- iOS利用Runtime自定义控制器POP手势动画
- 数据建模
- CoreData