-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Helena] Week 5 solutions #100
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
yolophg
commented
May 27, 2024
•
edited
Loading
edited
- Top K Frequent Elements
- Encode and Decode Strings
- Product of Array Except Self
- Longest Consecutive Sequence
- 3Sum
선 Draft PR, 후 문제 풀이! 좋습니다 👍 |
top-k-frequent-elements/yolophg.js
Outdated
const frequencyMap = new Map(); | ||
// for each number in the array, update frequency. | ||
for (const num of nums) { | ||
frequencyMap.set(num, (frequencyMap.get(num) || 0)); |
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을 더해주지 않으면, 항상 0이 되지 않나요? 😳
frequencyMap.set(num, (frequencyMap.get(num) || 0)); | |
frequencyMap.set(num, (frequencyMap.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.
헉, 놓친 부분을 지적해주셔서 감사합니다! 수정하여 반영하였습니다.
top-k-frequent-elements/yolophg.js
Outdated
if (buckets[i].length > 0) { | ||
result.push(...buckets[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.
if
문이 굳이 필요할까 하는 생각이 들었어요. result.push(...[])
는 아무 원소도 추가하지 않을테니까요.
if (buckets[i].length > 0) { | |
result.push(...buckets[i]); | |
} | |
result.push(...buckets[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.
그러게요, 빈 배열인 경우에는 불필요한 연산을 피해가기 위한 예외처리였는데 다시 생각해보니 애초에 굳이 없어도 될 것 같습니다!
피드백 감사합니다~ 반영해서 적용하였습니다!
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.
정렬이나 힙을 이용하지 않고, 배열의 인덱스에 빈도를 저장하디니, 굉장히 좋은 아이디어인 것 같습니다! 👍👍👍
이터레이션 설정 부탁드릴께용~ |
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.
let solution = new Solution();
solution.decode(solution.encode(['hello', '|world']))
이렇게 하면 깰 수 있을 것 같아요!
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.
오 decode하면 빈 스트링이 하나 추가되겠군요!
@yolophg PR이 아직 Draft 상태인데, 남은 두 문제 푸실 계획이신가요? |
넵! 마저 곧 업로드하겠습니다. 팔로업 감사드립니다. |
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.
수고하셨어용!
encode(strs) { | ||
// join the array into a single string using a delimiter, '|'. | ||
return strs.join('|'); | ||
} | ||
|
||
decode(str) { | ||
// split the string using the delimiter '|' and return the array. | ||
return str.split('|'); | ||
} |
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.
반칙? 🙈
[Helena] Week 5 solutions