# 448. Find All Numbers Disappeared in an Array

1. 遍历数组元素，将n[n[i] - 1]置负，再遍历一次，如果n[i]不为负，则i + 1没有出现。
2. 遍历数组元素，对于每一个元素，如果n[i] != i + 1 && n[n[i] - 1] != n[i]则调换n[i]n[n[i] - 1]直到上述条件成立，再遍历一次，如果n[i] != i + 1i + 1没有出现

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]

Solution#1

public class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list = new ArrayList<>();
if (nums == null || nums.length == 0) return list;
Arrays.sort(nums);
for (int i = 1; i < nums[0]; i++) {
}
for (int i = 0; i < nums.length - 1; i++) {
while (nums[i] < nums[i + 1] - 1) {
}
}
for (int i = nums[nums.length - 1] + 1; i <= nums.length; i++) {
}
return list;
}
}

Solution#2

public class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List list = new ArrayList<Integer>();
if (nums == null || nums.length == 0) return list;
for (int i = 0; i < nums.length; i++) {
while (nums[i] != i + 1 && nums[nums[i] - 1] != nums[i]) {
int tmp = nums[i];
nums[i] = nums[tmp - 1];
nums[tmp - 1] = tmp;
}
}
for (int i = 0; i < nums.length; i++) {
if (nums[i] != i + 1) {
}
}
return list;
}
}

• 本文已收录于以下专栏：

## LeetCode 448. Find All Numbers Disappeared in an Array

448. Find All Numbers Disappeared in an Array
• peisir
• 2017年07月21日 10:56
• 100

## leetcode-448 Find All Numbers Disappeared in an Array

leetcode-448 Find All Numbers Disappeared in an Array +-号标记

## LeetCode-448. Find All Numbers Disappeared in an Array (Java)

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot...
• 2017年06月11日 13:14
• 141

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

## LeetCode [448. Find All Numbers Disappeared in an Array] 难度[easy]

LeetCode [448. Find All Numbers Disappeared in an Array] 难度[easy]题目Given an array of integers where ...

## 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 ...
• BestFSQ
• 2017年02月25日 09:48
• 251

## leetcode448. Find All Numbers Disappeared in an Array

448. Find All Numbers Disappeared in an ArrayGiven an array of integers where 1 ≤ a[i] ≤ n (n = size...

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

## 448. Find All Numbers Disappeared in an Array \ 414. Third Maximum Number

448法一：class Solution { public: vector findDisappearedNumbers(vector& nums) { int nums_le...

## leetcode 448. Find All Numbers Disappeared in an Array

leetcode 448. Find All Numbers Disappeared in an ArrayQuestionGiven an array of integers where 1 ≤ a...

举报原因： 您举报文章：448. Find All Numbers Disappeared in an Array 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)