-
-
Notifications
You must be signed in to change notification settings - Fork 245
[Kyojin-Hwang] WEEK 01 solutions #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1주차 고생하셨습니다~!
.sort((a, b) => b[1] - a[1]) // 빈도 기준으로 정렬 | ||
.map((entry) => entry[0]); // 숫자만 추출 | ||
|
||
for (let i = 0; i < k; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return sorted.slice(0, k);
slice를 활용하면 바로 반환도 가능합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 그런 방법이 있었네용!!
|
||
return false; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var containsDuplicate = function (nums) {
const seen = new Set();
for (let num of nums) {
if (seen.has(num)) return true;
seen.add(num);
}
return false;
};
Set 자료구조를 사용한다면 중복을 제거하고 메모리, 속도 측면에서 좋다고 생각합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 의견 감사합니다!
const map = new Map(); | ||
|
||
for (let num of nums) { | ||
map.set(num, (map.get(num) || 0) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
js에서 Map 활용을 잘하시고 계시네요 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니댱!!
@hi-rachel 레이첼님 검토자 체크리스트 체크 한번만 부탁드리겠습니당 ㅎㅎ! |
검토자 체크 리스트 본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다! 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요. 어떤걸 확인하라는걸까요? |
그 체크가 안되어 있어서 체크 해주시는게 아닐까요? |
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!