LeetCode_448. Find All Numbers Disappeared in an Array
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.
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的更多相关文章
- 【leetcode】448. Find All Numbers Disappeared in an Array
problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...
- leetcode之Find All Numbers Disappeared in an Array
问题来源:Find All Numbers Disappeared in an Array 很久没有刷题了,感觉大脑开始迟钝,所以决定重拾刷题的乐趣.一开始不要太难,选一些通过率高的题目做,然后就看到 ...
- 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 = ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- LeetCode Find All Numbers Disappeared in an Array
原题链接在这里:https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/ 题目: Given an array o ...
- [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 ...
随机推荐
- 如何显示隐藏的文件在win7系统中
点左下角“开始”菜单,再点击“计算机”. 点击窗口顶部靠左位置的“组织”菜单,选择其中的“文件夹和搜索选项”. 在弹出的窗口里点击切换到“查看”选项卡. 在窗口中部位置下拉滚动条,找到“显示隐藏的 ...
- Mysql insert on update
数据库 Mysql INSERT INTO table (column_list) VALUES (value_list) ON DUPLICATE KEY UPDATE c1 = v1, c2 = ...
- JUnit 5.x 知识点
出处:https://blinkfox.github.io/2018/11/15/hou-duan/java/dan-yuan-ce-shi-zhi-nan/#toc-heading-14 表面上来看 ...
- C++输入输出流 cin/cout 及格式化输出简介
C++ 可通过流的概念进行程序与外界环境( 用户.文件等 )之间的交互.流是一种将数据自源( source )推送至目的地( destination )的管道.在 C++ 中,与标准输入/输出相关的流 ...
- python2和python3共存方法
拿到安装包,安装python3 centos: sudo yum install python36 ubuntu: sudo add-apt-repository ppa:deadsnakes/ppa ...
- python 查询文件存放地址
import os, time import sys import re def search(path,name): for root, dirs, files in os.walk(path): ...
- mcp2515屏蔽寄存器和过滤寄存器的学习
mcp2515是can控制器,简单的来讲,就是只要配置好寄存器,芯片就能够自动的解析can数据帧,同时保存到接收缓存中,提醒单片机可以读取can的数据字节. 读取的方式是快速spi,可以达到10Mbi ...
- react native 从创建到部署
source code: 开源库 rn源代码 native源代码 sourcecode tool: npm react-native vscode xocde.vscode ide+tools ...
- POJ3259-Wormholes-( spfa || Bellman_Ford )
题意:有n块田,之间有m条无向边表示路径,权值表示走过需要花费的时间.有w对虫洞,虫洞是单向的,表示穿越一定时间到过去,并且回到虫洞指向的点,问一个人有没有可能通过虫洞回到某个起点,并且在从这个起点出 ...
- UFUN函数 UF_CURVE函数(UF_CURVE_create_line、UF_CURVE_create_arc、UF_CURVE_ask_arc_data、UF_CURVE_ask_line_data)
UF_initialize(); //CSYS_ask_wcs tag_t wcs_id=NULL_TAG; //CSYS_ask_csys_info ]={0.0}; //CURVE_create_ ...