Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions contains-duplicate/Grit03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const countMap = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set 자료구조를 사용해보는 건 어떨까요?
참고자료 첨부드립니다! https://www.algodale.com/problems/contains-duplicate/#%ED%92%80%EC%9D%B4-3

한 주간 고생많으셨어요 🙌


for (let i = 0; i < nums.length; i++) {
const key = nums[i];
if (countMap.has(key)) {
const value = countMap.get(key);
if (value === 1) {
return true;
}
countMap.set(key, value + 1);
} else {
countMap.set(key, 1);
}
}

return false;
};