Question:
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
给定整数数组,查找数组是否包含任何重复项。
如果数组中至少出现两次值,则函数应返回true;如果每个元素不同,则函数应返回false
Example:
Input: [1,2,3,1]
Output: true
Input: [1,2,3,4]
Output: false
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true
Solution:
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
return new Set(nums).size < nums.length
};