Skip to content

Commit ee14026

Browse files
committed
contains duplicate
1 parent 53ce7c7 commit ee14026

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)