[리트코드] 217. Contains Duplicate
217. Contains Duplicate
나의 풀이
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const hash = nums.reduce((acc, cur) => {
acc[cur] = (acc[cur] || 0) + 1;
return acc;
}, {});
return Object.values(hash).some(v => v > 1);
};
console.log(containsDuplicate([1, 2, 3, 1]));
Runtime: 100 ms, faster than 39.06% of JavaScript online submissions for Contains Duplicate.
기본 방법 (효율성 bad)
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
return (new Set(nums)).size !== nums.length
};
와우 이게 뭐지?