题目要求

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements of [1, n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

题目分析及思路

给定一个整数数组,数组元素取值在1-n之间(n为数组长度)。有些元素出现了两次,有些只出现了一次。要求得到在范围1-n之间没有出现在数组中的值。可以使用集合来做,将1-n这个范围和给定数组转成集合,使用集合的差得到最后的结果。

python代码

class Solution:

def findDisappearedNumbers(self, nums: List[int]) -> List[int]:

return list(set(range(1,len(nums)+1))-set(nums))

LeetCode 448 Find All Numbers Disappeared in an Array 解题报告的更多相关文章

  1. 【LeetCode】448. Find All Numbers Disappeared in an Array 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 方法一:暴力求解 方法二:原地变负做标记 方法三:使用set ...

  2. LeetCode 448. Find All Numbers Disappeared in an Array (在数组中找到没有出现的数字)

    Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...

  3. leetcode 448. Find All Numbers Disappeared in an Array -easy (重要)

    题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...

  4. LeetCode "448. Find All Numbers Disappeared in an Array"

    My first reaction is to have an unlimited length of bit-array, to mark existence. But if no extra me ...

  5. 5. Leetcode 448. Find All Numbers Disappeared in an Array

    Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...

  6. LeetCode: 448 Find All Numbers Disappeared in an Array(easy)

    题目: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice an ...

  7. LeetCode 448. Find All Numbers Disappeared in an Array找到所有数组中消失的元素

    题目 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能 ...

  8. [LeetCode] 448. Find All Numbers Disappeared in an Array 找到数组中消失的数字

    题目描述 给定n个数字的数组,里面的值都是1-n,但是有的出现了两遍,因此有的没有出现,求没有出现值这个数组中的值有哪些. 要求不能用额外的空间(除了返回列表之外),时间复杂度n 思路 因为不能用额外 ...

  9. 【leetcode】448. Find All Numbers Disappeared in an Array

    problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...

随机推荐

  1. [转]awsome-java

    原文链接 Awesome Java A curated list of awesome Java frameworks, libraries and software. Contents Projec ...

  2. ###My SQL Date相关函数

    ###My SQL Date相关函数 #获得当前日期时间 select now(); #date_format(date,format) select date_format('2008-08-08 ...

  3. MVC5 IIS7 403错误

    问题背景 MVC5部署到IIS7中显示403错误. 解决方案 <system.webServer> → <modules> 节点下的 ApplicationInsightsWe ...

  4. react-native init的时候出现问题:npm WARN React-native@0.35.0 requires a peer of react@~15.3.1 but none was

    react-native init的时候出现问题:npm WARN React-native@0.35.0 requires a peer of react@~15.3.1 but none was ...

  5. nginx伪静态配置教程总结

    在nginx中配置伪静态,也就是常说的url重写功能,只需在nginx.conf配置文件中写入重写规则即可. 当然,这个规则是需要熟悉正则表达式,只掌握nginx自身的正则匹配模式即可,对正则不了解的 ...

  6. Atitit 3种类型的公司:运营驱动型;产品驱动型; 技术驱动型。

    Atitit  3种类型的公司:运营驱动型:产品驱动型: 技术驱动型. 领导驱动,产品驱动,运营驱动还是工程师驱动 3种类型的公司: 一种是运营驱动型: 一种是产品驱动型: 一种技术驱动型. 运营驱动 ...

  7. static在类中的功能

    有时候类需要它的一些成员与类本身直接相关,而不是与类的各个对象保持关联. 例如一个银行账户类可能需要一个数据成员来表示当前的利率.在此例中,我们希望利率与类关联,而非与类的每个对象关联.从实现效率上来 ...

  8. [转]decorators.xml的用法

    原文地址:https://blog.csdn.net/laozhuxiao/article/details/54342121 简介: sitemesh应用Decorator模式,用filter截取re ...

  9. oracle获取过去两年的今天时间

    获取过去两年的今天时间: SELECT last_day(ADD_MONTHS(ADD_MONTHS(sysdate,-12), ROWNUM - 1)) as monthlist FROM DUAL ...

  10. ubuntu cli

    查看安装包的路径 dpkg -L redis-server 防火墙 ufw redis 相关 service redis-server restart