Skip to content

Commit 75bcdb5

Browse files
committed
contains-duplicate solution
1 parent f291ae8 commit 75bcdb5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contains-duplicate/krokerdile.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
var containsDuplicate = function(nums) {
6+
let dict = new Map();
7+
8+
nums.forEach((num)=>{
9+
if(dict.has(num)){
10+
dict.set(num, dict.get(num)+1);
11+
}else{
12+
dict.set(num, 1);
13+
}
14+
})
15+
16+
for (const num of nums) {
17+
if(dict.get(num) >= 2){
18+
return true;
19+
}
20+
}
21+
return false;
22+
};

0 commit comments

Comments
 (0)