leetcode 448 Find All Numbers Disappeared in an Array

弓背霞明剑照霜,秋风走马出咸阳。这篇文章主要讲述leetcode 448 Find All Numbers Disappeared in an Array相关的知识,希望能为你提供帮助。

class Solution { public List< Integer> findDisappearedNumbers(int[] nums) {int n = nums.length; ArrayList< Integer> ans = new ArrayList< Integer> (); boolean[] vis = new boolean[n+1]; for(int i=0; i< n; i++){ vis[nums[i]] = true; } for(int i=1; i< =n; i++){ if(!vis[i]) ans.add(i); }return ans; } }

【leetcode 448 Find All Numbers Disappeared in an Array】时间复杂度O(n),空间复杂度O(n)。空间复杂度O(1)的不会做- -待补

    推荐阅读