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? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Difficulty: 简单
Related Topics: 数组, 哈希表, 排序
给你一个整数数组 nums 。如果任一值在数组中出现 至少两次 ,返回 true ;如果数组中每个元素互不相同,返回 false 。
nums
true
false
示例 1:
输入:nums = [1,2,3,1] 输出:true
示例 2:
输入:nums = [1,2,3,4] 输出:false
示例 3:
输入:nums = [1,1,1,3,3,4,3,2,4,2] 输出:true
提示:
Language: JavaScript
/** * @param {number[]} nums * @return {boolean} */ // 排序 // var containsDuplicate = function(nums) { // nums.sort((a, b) => a - b) // const n = nums.length // for (let i = 0; i < n - 1; i++) { // if (nums[i] === nums[i + 1]) { // return true // } // } // return false // }; // 哈希表 var containsDuplicate = function(nums) { const set = new Set() for (let x of nums) { if (set.has(x)) return true set.add(x) } return false };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
217. 存在重复元素
Description
Difficulty: 简单
Related Topics: 数组, 哈希表, 排序
给你一个整数数组
nums
。如果任一值在数组中出现 至少两次 ,返回true
;如果数组中每个元素互不相同,返回false
。示例 1:
示例 2:
示例 3:
提示:
Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: