Skip to content

[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

Merged
merged 11 commits into from
Jun 2, 2024
Merged

[Helena] Week 5 solutions #100

merged 11 commits into from
Jun 2, 2024

Conversation

yolophg
Copy link
Contributor

@yolophg yolophg commented May 27, 2024

  • Top K Frequent Elements
  • Encode and Decode Strings
  • Product of Array Except Self
  • Longest Consecutive Sequence
  • 3Sum

@yolophg yolophg marked this pull request as draft May 27, 2024 23:41
@DaleSeo
Copy link
Member

DaleSeo commented May 27, 2024

선 Draft PR, 후 문제 풀이! 좋습니다 👍

const frequencyMap = new Map();
// for each number in the array, update frequency.
for (const num of nums) {
frequencyMap.set(num, (frequencyMap.get(num) || 0));
Copy link
Member

Choose a reason for hiding this comment

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

1을 더해주지 않으면, 항상 0이 되지 않나요? 😳

Suggested change
frequencyMap.set(num, (frequencyMap.get(num) || 0));
frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

헉, 놓친 부분을 지적해주셔서 감사합니다! 수정하여 반영하였습니다.

Comment on lines 21 to 23
if (buckets[i].length > 0) {
result.push(...buckets[i]);
}
Copy link
Member

Choose a reason for hiding this comment

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

if 문이 굳이 필요할까 하는 생각이 들었어요. result.push(...[])는 아무 원소도 추가하지 않을테니까요.

Suggested change
if (buckets[i].length > 0) {
result.push(...buckets[i]);
}
result.push(...buckets[i]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

그러게요, 빈 배열인 경우에는 불필요한 연산을 피해가기 위한 예외처리였는데 다시 생각해보니 애초에 굳이 없어도 될 것 같습니다!
피드백 감사합니다~ 반영해서 적용하였습니다!

Copy link
Member

@DaleSeo DaleSeo May 28, 2024

Choose a reason for hiding this comment

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

정렬이나 힙을 이용하지 않고, 배열의 인덱스에 빈도를 저장하디니, 굉장히 좋은 아이디어인 것 같습니다! 👍👍👍

@DaleSeo DaleSeo self-requested a review May 28, 2024 00:22
@DaleSeo
Copy link
Member

DaleSeo commented May 28, 2024

이터레이션 설정 부탁드릴께용~

Copy link
Contributor

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']))

이렇게 하면 깰 수 있을 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

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

오 decode하면 빈 스트링이 하나 추가되겠군요!

@DaleSeo
Copy link
Member

DaleSeo commented Jun 2, 2024

@yolophg PR이 아직 Draft 상태인데, 남은 두 문제 푸실 계획이신가요?

@yolophg
Copy link
Contributor Author

yolophg commented Jun 2, 2024

@yolophg PR이 아직 Draft 상태인데, 남은 두 문제 푸실 계획이신가요?

넵! 마저 곧 업로드하겠습니다. 팔로업 감사드립니다.

@yolophg yolophg marked this pull request as ready for review June 2, 2024 18:00
@yolophg yolophg closed this Jun 2, 2024
@yolophg yolophg reopened this Jun 2, 2024
Copy link
Member

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

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

수고하셨어용!

Comment on lines +5 to +13
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('|');
}
Copy link
Member

Choose a reason for hiding this comment

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

반칙? 🙈

@DaleSeo DaleSeo merged commit 3e99718 into DaleStudy:main Jun 2, 2024
1 check passed
SamTheKorean pushed a commit to SamTheKorean/leetcode-study_Forked that referenced this pull request Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants