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 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]
package leetcode.easy;

public class FindAllNumbersDisappearedInAnArray {
public java.util.List<Integer> findDisappearedNumbers(int[] nums) {
boolean[] seenOrNot = new boolean[nums.length];
for (int i = 0; i < seenOrNot.length; i++) {
seenOrNot[i] = false;
}
for (int j = 0; j < nums.length; j++) {
seenOrNot[nums[j] - 1] = true;
}
java.util.ArrayList<Integer> unseen = new java.util.ArrayList<Integer>();
for (int i = 0; i < seenOrNot.length; i++) {
if (!seenOrNot[i]) {
unseen.add(i + 1);
}
}
return unseen;
} @org.junit.Test
public void test() {
int[] nums = { 4, 3, 2, 7, 8, 2, 3, 1 };
System.out.println(findDisappearedNumbers(nums));
}
}

LeetCode_448. Find All Numbers Disappeared in an Array的更多相关文章

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

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

  2. leetcode之Find All Numbers Disappeared in an Array

    问题来源:Find All Numbers Disappeared in an Array 很久没有刷题了,感觉大脑开始迟钝,所以决定重拾刷题的乐趣.一开始不要太难,选一些通过率高的题目做,然后就看到 ...

  3. 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 = ...

  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. LeetCode——Find All Numbers Disappeared in an Array

    LeetCode--Find All Numbers Disappeared in an Array Question Given an array of integers where 1 ≤ a[i ...

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

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

  8. LeetCode Find All Numbers Disappeared in an Array

    原题链接在这里:https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ 题目: Given an array o ...

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

随机推荐

  1. GStreamer: your gstreamer installation is missing a required plugin in funct

    # yum install gstreamer-plugins-* //问题依旧 别人回答: 编解码不对应? 我印象中GStreamer解码器分什么good,bad 取决你要读什么媒体,需要装些插件的 ...

  2. Win10上的Docker应用:Docker-compose(容器编排)

    阅读目录: Docker应用:Hello World Docker应用:Docker-compose(容器编排) 前言: 昨天完成了Docker入门示例(Docker应用:Hello World),示 ...

  3. 我的洛谷签名——Pale Blue Dot

    We succeeded in taking that picture [from deep space], and, if you look at it, you see a dot. That's ...

  4. sed命令基本用法

    sed是一个非交互式文本编辑器,它可对文本文件和标准输入进行编辑sed 适用于以下三种场合:编辑相对交互式文本编辑器而言太大的文件编辑命令太复杂,在交互式文本编辑器中难以输入的情况对文本扫描一遍,但是 ...

  5. python--requests模块初识

    requests,发送http请求(用python模拟浏览器浏览网页)requests.get("http://www.baidu.com") 示例: import request ...

  6. Reincarnation HDU - 4622 (后缀自动机)

    Reincarnation \[ Time Limit: 3000 ms\quad Memory Limit: 65536 kB \] 题意 给出一个字符串 \(S\),然后给出 \(m\) 次查询, ...

  7. LeetCode 490. The Maze

    原题链接在这里:https://leetcode.com/problems/the-maze/ 题目: There is a ball in a maze with empty spaces and ...

  8. kafka设计要点之高吞吐量

    2345678910111213141516 /** * Delete this log segment from the filesystem. * * @throws KafkaStorageEx ...

  9. 大数定律(Law of Large Numbers)

    大数定律:每次从总体中随机抽取1个样本,这样抽取很多次后,样本的均值会趋近于总体的期望.也可以理解为:从总体中抽取容量为n的样本,样本容量n越大,样本的均值越趋近于总体的期望.当样本容量极大时,样本均 ...

  10. svn报错:[Previous operation has not finished; run 'cleanup' if it was interrupted] 的排错过程

    今天在打开某一文档的情况下,使用SVN更新文档,在更新的过程中报错,提示需要执行clean up,果断右键执行clean up,又提示一个新的错误:"Previous operation h ...