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 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 解题报告的更多相关文章
- 【LeetCode】448. Find All Numbers Disappeared in an Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 方法一:暴力求解 方法二:原地变负做标记 方法三:使用set ...
- 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 ...
- leetcode 448. Find All Numbers Disappeared in an Array -easy (重要)
题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...
- 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. 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 ...
- 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 ...
- LeetCode 448. Find All Numbers Disappeared in an Array找到所有数组中消失的元素
题目 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能 ...
- [LeetCode] 448. Find All Numbers Disappeared in an Array 找到数组中消失的数字
题目描述 给定n个数字的数组,里面的值都是1-n,但是有的出现了两遍,因此有的没有出现,求没有出现值这个数组中的值有哪些. 要求不能用额外的空间(除了返回列表之外),时间复杂度n 思路 因为不能用额外 ...
- 【leetcode】448. Find All Numbers Disappeared in an Array
problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...
随机推荐
- CentOS 6.5 x64下安装宝塔面板、阿里安骑士
一.安装宝塔: CentOS下命令(https://www.bt.cn/bbs/thread-1186-1-1.html) yum install -y wget && wget -O ...
- Spring Boot系列——日志配置
日志,通常不会在需求阶段作为一个功能单独提出来,也不会在产品方案中看到它的细节.但是,这丝毫不影响它在任何一个系统中的重要的地位. 为了保证服务的高可用,发现问题一定要即使,解决问题一定要迅速,所以生 ...
- The thumbprint of same asymmetric key is not same in 'SQL Server Connector for Microsoft Azure Key Vault' 1.0.4.0 and 'SQL Server Connector for Microsoft Azure Key
https://support.microsoft.com/en-us/help/4470999/db-backup-problems-to-sql-server-connector-for-azur ...
- Atitit uke公司简介与基本制度建设草案v11 r66 .docx
Atitit uke公司简介与基本制度建设草案v11 r66 .docx Uke org prj Author撰写人: 作者:: 绰号:老哇的爪子claw of Eagle 偶像破坏者Iconocl ...
- HADOOP security
https://www.microsoft.com/en-us/trustcenter/security/azure-security https://docs.microsoft.com/en-us ...
- Linux时区详解
全球24个时区的划分 相较于两地时间表,可以显示世界各时区时间和地名的世界时区表(World Time),就显得精密与复杂多了,通常世界时区表的表盘上会标示着全球24个时区的城市名称,但究竟这24个时 ...
- Canvas入门到高级详解(中)
三. canvas 进阶 3.1 Canvas 颜色样式和阴影 3.1.1 设置填充和描边的颜色(掌握) fillStyle : 设置或返回用于填充绘画的颜色 strokeStyle: 设置或返回用于 ...
- Linux 设备树属性在驱动中获取方法
获取设备树中的属性,可以直接当设备树为配置文件,方便,快捷. 一般probe之后,调用的 probe函数的参数, 是一个设备结构体. 拿 spi 为例子 static int wk2xxx_probe ...
- docker被屏蔽后下载方法
docker镜像默认的官网上传平台:https://hub.docker.com/,k8s运行时需要从google下载镜像(k8s.gcr.io),但该网被屏蔽了,怎样下载到所需镜像呢? 1. 可在知 ...
- mac 环境变量
在 ~/.bash_profile 中添加一行: export PATH=$PATH:/usr/local/bin 其中,/usr/local/bin 为需要添加的 path 执行 source .b ...