题目要求

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. SQL DDL 数据定义语句

    前言 DDL(Data Definition Language)语句:数据定义语句,这些语句定义了不同的数据段.数据库.表.列.索引等数据库对象.常用的语句关键字主要包括 create.drop.al ...

  2. .net core 2.0+superui +Dapper.SimpleCRUD+mysql+NLog

    **_ .net core 2.0+superui +Dapper.SimpleCRUD+mysql+NLog _** 前端框架 superui http://www.supermgr.cn/ 1.组 ...

  3. 2D空间的OBB碰撞实现

    OBB全称Oriented bounding box,方向包围盒算法.其表现效果和Unity的BoxCollider并无二致.由于3D空间的OBB需要多考虑一些情况 这里仅关注2D空间下的OBB. 实 ...

  4. RSA/SHA1加密和数字签名算法在开放平台中的应用

    加密算法 加密算法分为两大类:1.对称加密算法:2.非对称加密算法.   密钥个数 加密 解密 对称加密 一个 使用密钥加密 使用同一个密钥解密 非对称加密 两个,公钥和私钥 使用其中一把密钥加密 使 ...

  5. git clone 后误删除了分离出来的文件怎么恢复?

    git clone 后,会分离出项目的文件. 误删除了,可以使用以下命令恢复: #先检查一下git状态 git status #通过如下命令重新分离出文件 git checkout -f HEAD

  6. spring boot 配置注入

    spring boot配置注入有变量方式和类方式(参见:<spring boot 自定义配置属性的各种方式>),变量中又要注意静态变量的注入(参见:spring boot 给静态变量注入值 ...

  7. Linux系统时间同步方法小结

    在Windwos中,系统时间的设置很简单,界面操作,通俗易懂,而且设置后,重启,关机都没关系.系统时间会自动保存在BIOS时钟里面,启动计算机的时候,系统会自动在BIOS里面取硬件时间,以保证时间的不 ...

  8. 图像的下采样Subsampling 与 上采样 Upsampling

     I.目的 缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的: 1.使得图像符合显示区域的大小: 2.生成对应图像的缩略图. 放大图像(或称为上采样(ups ...

  9. 同时执行多个$.getJSON() 数据混乱的问题的解决

    在执行之前加$.ajaxSettings.async = false; (同步执行)执行你的代码之后及时恢复为$.ajaxSettings.async = true: (异步执行)不然影响别的地方的需 ...

  10. MXPlayer ac3音轨支持问题

    下载的MXPlayer 在播放kvm视频的时候没有声音, 说是不支持ac3的音频 到官网下载单独的解码包: https://mxplayerdownloads.com/mx-player-ac3-dt ...