Skip to content

Commit 19588b2

Browse files
authored
Merge pull request #1725 from Grit03/main
[Grit03] WEEK 01 solutions
2 parents b580e8f + ee14026 commit 19588b2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

contains-duplicate/Grit03.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+
const countMap = new Map();
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
const key = nums[i];
10+
if (countMap.has(key)) {
11+
const value = countMap.get(key);
12+
if (value === 1) {
13+
return true;
14+
}
15+
countMap.set(key, value + 1);
16+
} else {
17+
countMap.set(key, 1);
18+
}
19+
}
20+
21+
return false;
22+
};

0 commit comments

Comments
 (0)