Description

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:
[,,,,,,,] Output:
[,]

问题描述:给定一个数组,1 ≤ a[i] ≤ n (n为数据的长度)  数组中有的元素出现一次,有的出现两次,找到数组中没有出现的元素

思路:先遍历一遍做标记,然后再遍历一次,找到没有出现的元素

public IList<int> FindDisappearedNumbers(int[] nums) {
//Array.Sort(nums);
IList<int> res = new List<int>();
for(int i = ; i < nums.Length; i++){
int index = Math.Abs(nums[i])-;
if(nums[index] > ){
nums[index] = - * nums[index];
}
}
for(int i = ; i < nums.Length; i++){
if(nums[i] > ){
res.Add(i+);
}
}
return res;
}

LeetCode Array Easy 448. Find All Numbers Disappeared in an Array的更多相关文章

  1. [LeetCode&Python] Problem 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 ...

  2. 448. Find All Numbers Disappeared in an Array【easy】

    448. Find All Numbers Disappeared in an Array[easy] Given an array of integers where 1 ≤ a[i] ≤ n (n ...

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

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

  4. leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array

    后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...

  5. 448. Find All Numbers Disappeared in an Array&&645. Set Mismatch

    题目: 448. Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = ...

  6. 448. Find All Numbers Disappeared in an Array@python

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

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

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

  8. 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 ...

  9. 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 ...

随机推荐

  1. Windows系统中,循环运行.bat/.exe等文件

    一.创建循环运行的run-everySecond.vbs文件[双击次文件即可启动运行] dim a set a=CreateObject("Wscript.Shell") Do # ...

  2. 三、ARM 寄存器及异常处理

    3.1 ARM 内部寄存器 ARM920T 总共有 37 个寄存器,其中 31 通用 32 位寄存器和 6 个状态寄存器,但不能在同一时刻对所有的寄存器可见.处理器状态和运行模式决定了哪些寄存器对程序 ...

  3. tensor与数组转化

    import tensorflow as tfimg1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[ ...

  4. 在父组件中,直接获取子组件数据-vue

    1.通过 $ref 获取 主父组件中: <x-test ref="ch"></x-test> import XTest from '@/components ...

  5. django之创建子应用

    一:子应用 Django的视图编写是放在子应用中的.类似于flask中的视图. 二:创建子应用 例如:在刚才的dj_study项目中,创建一个名字为user的子应用(目录):注意是第一级的dj_stu ...

  6. 036:DTL常用过滤器(5)

    slice过滤器: 类似于 Python 中的切片操作.示例代码如下: {{ some_list|slice:"2:" }} 以上代码将会给 some_list 从 2 开始做切片 ...

  7. BZOJ 1096: [ZJOI2007]仓库建设 动态规划 + 斜率优化

      #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #defi ...

  8. 让VirtualBox虚拟机实现开机自动后台运行

    转至:http://www.cnblogs.com/top5/archive/2012/01/19/2326234.html 测试环境:Host OS: Windows 7 x64 Guest OS: ...

  9. 【转】iis解决应用程序池**提供服务的进程意外终止进程ID是**。进程退出代码是'0x80'

    转自:http://blog.sina.com.cn/s/blog_56a68d5501013xdd.html 我们公司旗下的红黑互联会遇到这种问题 事件类型: 警告事件来源: W3SVC事件种类: ...

  10. Ponds

    Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...