Skip to content

Latest commit

 

History

History
57 lines (35 loc) · 1.48 KB

0448-find-all-numbers-disappeared-in-an-array.adoc

File metadata and controls

57 lines (35 loc) · 1.48 KB

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]

解题分析

原地修改的思路有点绕。再推敲推敲。

0448 1
0448 2
0448 3

参考资料

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]
link:{sourcedir}/_0448_FindAllNumbersDisappearedInAnArray.java[role=include]