leetcode 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements of 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:
Output:
class Solution {
public List<Integer> findDisappearedNumbers(int[] nums) {
List<Integer> list = new ArrayList<>();
if(nums.length == 0) return list;
int[] arr = new int;
for(int i = 0; i< nums.length ; i++) arr]++;
for(int i = 1; i< arr.length; i ++)
{
if(arr == 0) list.add(i);
}
return list;
}
}
页:
[1]