Skip to content

Commit e1cbafe

Browse files
committed
containsDuplicate solution2
1 parent a815638 commit e1cbafe

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

contains-duplicate/hyejj19.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
function containsDuplicate(nums: number[]): boolean {
2-
const numsMap = new Map();
3-
nums.forEach(n => {
4-
numsMap.set(n, (numsMap.get(n) || 0) + 1);
5-
});
6-
7-
for (const [_, count] of numsMap) {
8-
if (count >= 2) return true;
9-
}
10-
11-
return false;
2+
return new Set(nums).size !== nums.length;
123
}

0 commit comments

Comments
 (0)