给定一个范围在  1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。

找到所有在 [1, n] 范围之间没有出现在数组中的数字。

您能在不使用额外空间且时间复杂度为O(n)的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。

示例:

输入: [4,3,2,7,8,2,3,1] 输出: [5,6]

class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
int len = nums.size();
map<int, int> check;
vector<int> res;
for (int i = 0; i < len; i++)
{
check[nums[i]]++;
}
for (int i = 1; i <= len; i++)
{
if (check[i] == 0)
res.push_back(i);
}
return res;
}
};

Leetcode448.Find All Numbers Disappeared in an Array找到所有数组中消失的数字的更多相关文章

  1. 448 Find All Numbers Disappeared in an Array 找到所有数组中消失的数字

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

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

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

  3. [Swift]LeetCode448. 找到所有数组中消失的数字 | 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 ...

  4. [LeetCode] 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 ...

  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. lintcode :Remove Duplicates from Sorted Array 删除排序数组中的重复数字

    题目: 删除排序数组中的重复数字 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成.  样例 ...

  7. C#LeetCode刷题之#448-找到所有数组中消失的数字(Find All Numbers Disappeared in an Array)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3712 访问. 给定一个范围在  1 ≤ a[i] ≤ n ( n ...

  8. 【LeetCode每天一题】Find First and Last Position of Element in Sorted Array(找到排序数组中指定元素的开始和结束下标)

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  9. LeetCode-448. Find All Numbers Disappeared in an Array C#

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

随机推荐

  1. python元祖,join(),range()

    一.元祖定义 元组:俗称不可变的列表,又被成为只读列表,元祖也是python的基本数据类型之一,用小括号括起来,里面可以放任何数据类型的数据,查询可以,循环也可以,切片也可以.但就是不能改. 儿子不能 ...

  2. HYNB Contest 7:2017 Asia HCMC Vietnam National Programming Contest

    A. Another Query on Array Problem B. Board Covering C. Cumulative Sums 题意 \(A_1=1,A_i=A_{i-1}+sod(A_ ...

  3. POJ 2932 平面扫描 /// 判断圆的包含关系

    题目大意: 平面上有n个两两不相交的圆,给定圆的圆心(x,y)和半径 r 求所有最外层的 即 不包含于其他圆内部的圆 挑战258页 平面扫描 记录所有圆的左端和右端 排序后 逐一扫描 将到当前圆为止的 ...

  4. JPA默认方法查询遇到转JSON的处理

    JPA提供的findAll等查询方法在有关联的对象时 比如:在查userInfo @Entity@Table(name = "user_info")public class Use ...

  5. 2019-8-31-dotnet-通过-WMI-获取系统启动的服务

    title author date CreateTime categories dotnet 通过 WMI 获取系统启动的服务 lindexi 2019-08-31 16:55:59 +0800 20 ...

  6. MySQL中\g和\G的作用

    \g的作用和MySQL中的分号”;"是一样: \G的作用是讲查找到的内容结构旋转90度,变成纵向结构: 下面举例说明,查找数据库中的存在的存储过程状态: SHOW PROCEDURE STA ...

  7. MFC 使程序不在任务栏显示

    在OnInitDialog()中直接修改窗口风格: // 让本程序不在任务栏显示(创建一个工具条窗口) ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);

  8. Webstorm在MAC下的安装方法

    一 .注册时,在打开的License Activation窗口中选择“License server”,在输入框输入下面的网址: http://idea.codebeta.cn (新,感谢Rachels ...

  9. sql不用拼接语句实现动态查询条件

    DECLARE @oFrom INT SELECT * FROM baseinfo AND ( ( and Type = 'Breakfast') ) or的条件可自由添加,尤其适用互斥条件的查询.

  10. win7+64位笔记本安装TensorFlow CPU版

    最近要用到Keras框架,而Keras是基于Theano或Tensorflow框架安装的,所以首先要准备底层框架的搭建. 在网上看了一大堆教程头昏脑涨,随便挑了个试一试,竟然捣鼓成功了,记录一下安装过 ...