Skip to content

Commit c28406f

Browse files
committed
Contains Duplicate
1 parent 5274c46 commit c28406f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Contains Duplicate.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*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.*/
2+
3+
/**
4+
* @param {number[]} nums
5+
* @return {boolean}
6+
*/
7+
var containsDuplicate = function(nums) {
8+
var s = new Set()
9+
for(i=0; i<nums.length; i++){
10+
if(s.has(nums[i]))
11+
return true
12+
s.add(nums[i])
13+
}
14+
return false
15+
};

0 commit comments

Comments
 (0)