Contains Duplicate
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.
https://leetcode.com/problems/contains-duplicate/
水一题调节心情。
1 /** 2 * @param {number[]} nums 3 * @param {number} k 4 * @return {boolean} 5 */ 6 var containsDuplicate = function(nums) { 7 var set = new Set(); 8 for(var i in nums){ 9 if(set.has(nums[i])){ 10 return true; 11 }else{ 12 set.add(nums[i]); 13 } 14 } 15 return false; 16 };