mycode

class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums:
return 1
nums = sorted(nums)
max_n = max(nums)
for i in range(1,max_n+1):
if i not in nums:
return i
return max_n + 1
Runtime Error Message:Line 11: MemoryError
Last executed input:[2147483647]
 
44.76%
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums:
return 1
if 1 not in nums:
return 1
else:
nums = sorted(set(nums))
pos = nums.index(1)
if pos == len(nums) -1:
return 2
else:
nums[:] = nums[pos:]
for i in range(1,len(nums)):
if not i+1 == nums[i]:
return i + 1
return len(nums) + 1

参考

class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
l = range(0,-len(nums)-1,-1) [0,-1,-2,-3...]
print(l)
if not len(nums):
return 1 for n in nums:
if n < len(l) and n > 0:
l[n] = n for n in l:
if n < 0:
return -n return len(l)

leetcode-hard-array-41. First Missing Positive-NO的更多相关文章

  1. [array] leetcode - 41. First Missing Positive - Hard

    leetcode - 41. First Missing Positive - Hard descrition Given an unsorted integer array, find the fi ...

  2. [Leetcode][Python]41: First Missing Positive

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 41: First Missing Positivehttps://oj.le ...

  3. LeetCode题解41.First Missing Positive

    41. First Missing Positive Given an unsorted integer array, find the first missing positive integer. ...

  4. LeetCode - 41. First Missing Positive

    41. First Missing Positive Problem's Link ---------------------------------------------------------- ...

  5. 刷题41. First Missing Positive

    一.题目说明 题目是41. First Missing Positive,求一个未排序队列中缺失的最小正整数.时间复杂度要求是O(n).难度是Hard,确实难. 二.我的解答 不考虑时间复杂度,首先对 ...

  6. [LeetCode] 41. First Missing Positive 首个缺失的正数

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...

  7. leetcode 41 First Missing Positive ---java

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  8. 【一天一道LeetCode】#41. First Missing Positive

    一天一道LeetCode系列 (一)题目 Given an unsorted integer array, find the first missing positive integer. For e ...

  9. Java [Leetcode 41]First Missing Positive

    题目描述: Given an unsorted integer array, find the first missing positive integer. For example,Given [1 ...

  10. leetcode problem 41 -- First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

随机推荐

  1. 用Python输出一个Fibonacci数列

    斐波那契数列(Fibonacci sequence),又称黄金分割数列.因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列” 用文字来说, ...

  2. FileStrem大文件分割复制

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. BLE 5协议栈-通用属性规范层(GATT)

    文章转载自:http://www.sunyouqun.com/2017/04/page/2/ 通用属性规范GATT(Generic Attribute Profile)将ATT层定义的属性打包成不同的 ...

  4. python函数:装饰器、修正、语法糖、有参装饰器、global与nonlocal

    一.装饰器 二.装饰器修正1 三.装饰器修正2 四.装饰器的语法糖 五.有参.无参装饰器 六.global与nonlocal 一.装饰器 ''' 1 什么是装饰器 器=>工具 装饰=>指的 ...

  5. Java语言开发的,直接解压即可使用软件

    Tomcat ZooKeeper ActiveMQ Mycat

  6. “联邦对抗技术大赛”9月开战 微众银行呼唤开发者共同“AI创新”

    “联邦对抗技术大赛”9月开战  微众银行呼唤开发者共同“AI创新”   从<第五元素>中的智能系统到<超体>中的信息操控,在科幻电影中人工智能已经发展到了极致.而在现实中,目前 ...

  7. java中activiti框架中的排他网关使用方法,多条件判断

    当排他网关的判断条件中出现多个条件时,需要注意,设置判断条件时,可能遇到,流向相同的任务,而判断条件的变量个数不同 那么,必须在后面的运行任务时,将所有的涉及到的变量都设置进任务中,只不过,如果这个任 ...

  8. java8学习之Lambda表达式继续探讨&Function接口详解

    对于上次[http://www.cnblogs.com/webor2006/p/8186039.html]已经初步引入的Java8中Stream流的概念,其中使用了map的操作,它需要接受一个Func ...

  9. BZOJ4777 [Usaco2017 Open]Switch Grass[最小生成树+权值线段树套平衡树]

    标题解法是吓人的. 图上修改询问,不好用数据结构操作.尝试转化为树来维护.发现(不要问怎么发现的)最小生成树在这里比较行得通,因为最近异色点对一定是相邻的(很好想),所以只要看最短的一条两端连着异色点 ...

  10. ogg12c 配置

    环境:source 192.168.2.182 : 系统:Windows Server 2012 oracle: Release 12.1.0.2.0 ogg: 12.2.0.2.3 target 1 ...