博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode]python 448. Find All Numbers Disappeared in an Array
阅读量:4623 次
发布时间:2019-06-09

本文共 723 字,大约阅读时间需要 2 分钟。

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.

Example:

Input:[4,3,2,7,8,2,3,1]Output:[5,6]

在一个1到n的数组中,找到没有的数字并存放到一个数组中返回

 

class Solution:

def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
s = set(nums)
res = []
for x in range(1, len(nums) + 1):
if x not in s:
res.append(x)
return res

l = [4, 3, 2, 7, 8, 2, 3, 1]
print(Solution.findDisappearedNumbers(Solution, l))

转载于:https://www.cnblogs.com/ruoh3kou/p/8707752.html

你可能感兴趣的文章
redis 持久化
查看>>
解决Jupyter notebook[import tensorflow as tf]报错
查看>>
Windows平台下使用ffmpeg和segmenter实现m3u8直播点播
查看>>
python网络画图——networkX
查看>>
ubuntu16.04文件形式安装mongodb
查看>>
SpringBoot------ActiveMQ安装
查看>>
详细了解 int? 类型
查看>>
字符串匹配 ?kmp : hash
查看>>
mongod.service: control process exited, code=exited status=1
查看>>
c# 发送邮件、附件 分类: C# 2014-12-...
查看>>
对360来说,江湖上再无“搜狗”这个传说
查看>>
composer
查看>>
OpenCV特征点检测——ORB特征
查看>>
mysql的csv数据导入与导出
查看>>
leetcode笔记:Pascal's Triangle
查看>>
ASP.NET性能优化之构建自定义文件缓存
查看>>
Shell——windows上写完放入linux的时候需要注意的问题
查看>>
65条常用的正则表达式
查看>>
Vscode断点调试PHP
查看>>
做前端要做的6大事
查看>>