448. Find All Numbers Disappeared in an Array
https://leetcode.com/problems/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:
由[1, N]组成的N个数,其中的数可能出现一次或两次,找[1, N]中没有出现过的,要求O(N)时间和O(1)额外空间。因为O(1)空间,排除hash set。找missing/duplicate还有在原数组标记和XOR两种方法。由于范围是自然数,可在原数组取负作为标记。
Previous1465. Maximum Area of a Piece of Cake After Horizontal and Vertical CutsNext1422. Maximum Score After Splitting a String
Last updated
Was this helpful?