mycode

  1. class Solution(object):
  2. def firstMissingPositive(self, nums):
  3. """
  4. :type nums: List[int]
  5. :rtype: int
  6. """
  7. if not nums:
  8. return 1
  9. nums = sorted(nums)
  10. max_n = max(nums)
  11. for i in range(1,max_n+1):
  12. if i not in nums:
  13. return i
  14. return max_n + 1
Runtime Error Message:Line 11: MemoryError
Last executed input:[2147483647]
 
44.76%
  1. class Solution(object):
  2. def firstMissingPositive(self, nums):
  3. """
  4. :type nums: List[int]
  5. :rtype: int
  6. """
  7. if not nums:
  8. return 1
  9. if 1 not in nums:
  10. return 1
  11. else:
  12. nums = sorted(set(nums))
  13. pos = nums.index(1)
  14. if pos == len(nums) -1:
  15. return 2
  16. else:
  17. nums[:] = nums[pos:]
  18. for i in range(1,len(nums)):
  19. if not i+1 == nums[i]:
  20. return i + 1
  21. return len(nums) + 1

参考

  1. class Solution(object):
  2. def firstMissingPositive(self, nums):
  3. """
  4. :type nums: List[int]
  5. :rtype: int
  6. """
  7. l = range(0,-len(nums)-1,-1) [0,-1,-2,-3...]
  8. print(l)
  9. if not len(nums):
  10. return 1
  11.  
  12. for n in nums:
  13. if n < len(l) and n > 0:
  14. l[n] = n
  15.  
  16. for n in l:
  17. if n < 0:
  18. return -n
  19.  
  20. 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. another-redis-desktop-manager

    brew cask install another-redis-desktop-manager

  2. MySQL之concat、concat_ws、group_concat

    concat(str1, str2, ...)  返回结果为连接一起的字符串. concat_ws(separator, str1, str2, ...) 同concat,但是可以指定连接符,sepa ...

  3. ubantu32位 linux下hexedit的下载安装

    Hexedit软件介绍: hexedit是一个开源的完全免费的命令行软件,可用于在任何GNU / Linux操作系统下以十六进制和ASCII(美国信息交换标准代码)格式查看和编辑文件. 下载: 在so ...

  4. CUDA和TensorFlow的版本匹配问题

    CUDA和TensorFlow的版本匹配问题 部分转载自博客:https://blog.csdn.net/MahoneSun/article/details/80809042 列举一些CUDA和Ten ...

  5. Linux FTP 命令全集

    Linux FTP 命令全集 1 前言 下面就所有命令给出解释和例子. 说明:  1. remote-file 指远程文件,即服务器上的文件 2. local-file  指本地文件,即本地机器上的文 ...

  6. Git 简要教程

    Git是一个管理系统,管理版本,管理内容(CMS),管理工作等. Git主要还是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. 工作流程是这样的: 克隆 Git 资源作为工作目录 ...

  7. zencart重置用户登录密码sql

    zencart重置用户ID为99的登录密码为aaaaaaa ;

  8. 第二章 Vue快速入门--12 事件修饰符的介绍

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  9. Autoprefixer:一个以最好的方式处理浏览器前缀的后处理程序

    Autoprefixer解析CSS文件并且添加浏览器前缀到CSS规则里,使用Can I Use的数据来决定哪些前缀是需要的.   所有你需要做的就是把它添加到你的资源构建工具(例如 Grunt)并且可 ...

  10. 下载Mybatis源码

    百度搜索关键字:Mybatis 点击第二个选项,为啥不是第一个?因为卡. 打开之后,长这个样子: 点击画红圈的位置,进入github源码库: 发现,进入的太深了.点击mybatis-3,进到外层目录, ...