We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 简单
Related Topics: 数组, 哈希表
给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1, n] 内。请你找出所有在 [1, n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。
n
nums
nums[i]
[1, n]
示例 1:
输入:nums = [4,3,2,7,8,2,3,1] 输出:[5,6]
示例 2:
输入:nums = [1,1] 输出:[2]
提示:
n == nums.length
1 <= nums[i] <= n
**进阶:**你能在不使用额外空间且时间复杂度为O(n)的情况下解决这个问题吗? 你可以假定返回的数组不算在额外空间内。
O(n)
Language: JavaScript
/** * @param {number[]} nums * @return {number[]} */ var findDisappearedNumbers = function(nums) { const map = new Map(), res = []; for (const num of nums) { map.set(num, true) } for (let i = 1; i <= nums.length; i++) { if (!map.get(i)) { res.push(i) } } return res };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
448. 找到所有数组中消失的数字
Description
Difficulty: 简单
Related Topics: 数组, 哈希表
给你一个含
n
个整数的数组nums
,其中nums[i]
在区间[1, n]
内。请你找出所有在[1, n]
范围内但没有出现在nums
中的数字,并以数组的形式返回结果。示例 1:
示例 2:
提示:
n == nums.length
1 <= nums[i] <= n
**进阶:**你能在不使用额外空间且时间复杂度为
O(n)
的情况下解决这个问题吗? 你可以假定返回的数组不算在额外空间内。Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: