leetcode 448 Find All Numbers Disappeared in an Array
Posted ctqchina
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; } }
时间复杂度O(n),空间复杂度O(n)。空间复杂度O(1)的不会做- -待补
以上是关于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
LeetCode 448. Find All Numbers Disappeared in an Array
LeetCode - 448. Find All Numbers Disappeared in an Array