给定一个数组,找出数组中不曾出现的最小正整数。

关键在于需要对原数组进行操作。

class Solution:def firstMissingPositive(self, nums):""":type nums: List[int]:rtype: int"""if not nums: return 1for i in range(len(nums)):while 0 < nums[i] < len(nums) and nums[nums[i] - 1] != nums[i]:temp = nums[i]nums[i] = nums[temp - 1]nums[temp - 1] = tempprint(nums)for i in range(len(nums)):if nums[i] != i + 1:return i + 1return len(nums)+1

转载于:https://www.cnblogs.com/weiyinfu/p/8506854.html

leetcode41. First Missing Positive相关推荐

  1. Leetcode41.First Missing Positive

    大意:输出数组中未出现过的最小整数 简单思路: 1.排序,然后找到第一个不符合A[i]=i+1的元素即为正确答案.时间:O(nlgn) 额外空间:O(1) 2.一个哈希记录表,将所有出现过的元素记录为 ...

  2. [Swift]LeetCode41. 缺失的第一个正数 | First Missing Positive

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  3. 41-First Missing Positive

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

  4. LeetCode First Missing Positive

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

  5. Lintcode189 First Missing Positive solution 题解

    [题目描述] Given an unsorted integer array, find the first missing positive integer. 给出一个无序的整数数组,找出其中没有出 ...

  6. 41. First Missing Positive

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

  7. leetcode 41. First Missing Positive 1

    题目要求 Given an unsorted integer array, find the first missing positive integer.For example, Given [1, ...

  8. LeetCode题解41.First Missing Positive

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

  9. [LeetCode] First Missing Positive

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

最新文章

  1. PTA ---结构错题汇总
  2. ASP.NET 获取IIS应用程序池的托管管道模式
  3. Apache Ant安装 验证
  4. python代码评测结果tle_Python的备忘细节小抄
  5. PCA目标函数的推导
  6. FreeRTOS 的命名规则
  7. react中axios的二次封装
  8. 图卷积神经网络(part5)--GraphSAGE
  9. 复旦大学提出《Meta-FDMixup》解决跨域小样本学习中的域偏移问题
  10. Swagger2接口注释参数使用数组
  11. HDFS Federation机制
  12. HTML5新增的属性(八)
  13. React Web开发中常见的异常提示以及解决方案
  14. 精通javascript 代码总结
  15. 利用Word2Vec在语料中构建种子词集同类词
  16. Html中的favicon ico
  17. 基于Python的拉勾网的模拟登录获取cookie
  18. 超详细dns劫持解决办法分享
  19. 从新手到高手c++全方位学习 pdf + 视频教程 共18章
  20. 加密算法学习(一、中、1)——传统加密算法(playfair密码)

热门文章

  1. PyQT5-QProgressBar
  2. sklearn的快速使用
  3. 给mac配置adb 路径
  4. Android网络通信的六种方式
  5. 用批处理启动常用服务
  6. 数据文件坏删除数据文件
  7. 【MyBatis笔记】16-多对多关系建表
  8. Flex控制对主机网页中脚本的访问
  9. 华为推出鸿蒙超级系统,华为鸿蒙系统正式发布!十个人里竟然只有两个人支持?...
  10. php mysql addslashes_PHP函数 mysql_real_escape_string 与 addslashes 的区别