Skip to content

[아현] Week01 Solutions #314

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 8 commits into from
Aug 19, 2024
Merged

[아현] Week01 Solutions #314

merged 8 commits into from
Aug 19, 2024

Conversation

f-exuan21
Copy link
Contributor

@f-exuan21 f-exuan21 commented Aug 12, 2024

  • Contains Duplicate
  • Number of 1 Bits
  • Top K Frequent Elements
  • Kth Smallest Element In a Bst
  • Palindromic Substrings

@yolophg
Copy link
Contributor

yolophg commented Aug 12, 2024

안녕하세요, 코치 Helena 입니다.
아직 풀이가 다 완료되신 것 같지 않은데, draft로 변경해주시면 감사드리겠습니다 :)
자세한 사항은 위키를 확인해주세요!
=> https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C

추가로, 아래 사진과 같이 Projects 에서 iteration 설정도 같이 부탁드립니다!
이번엔 제가 해두었는데, 원할한 스터디 그룹 진도 관리와 통계를 위해서 중요한 부분이니 다음 이터레이션부터는 해주시면 감사드리겠습니다 :)
Screenshot 2024-08-12 at 11 41 08

@f-exuan21 f-exuan21 marked this pull request as draft August 12, 2024 21:47

class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> set = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

알고리즘과 관련없는 이야기인데

변수 선언을

Set<Integer> set = new HashSet<>();

으로 하는게 자바 컨벤션상 더 좋지 않을까 생각이 들었습니다.

public int[] topKFrequent(int[] nums, int k) {
Map<Integer, Integer> map = new HashMap<>();
for(int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

(그냥 의견)

merge 함수를 써보시는것도 좋을 수 있을 것 같습니다.

e.g.

map.merge(num, 1, Integer::sum);


// time : O(n) + O(m log m) + O(k log m) = O(n + m*logm + k*logm)
//
// 최악의 경우 n log n 이 될 수 있음
Copy link
Contributor

@dev-jonghoonpark dev-jonghoonpark Aug 15, 2024

Choose a reason for hiding this comment

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

n log n 으로 정리해주시면 되지 않을까 생각됩니다.

저도 1기 때 좀 많이 조언 받은건데
가능하면 문제에서 제시된 문자로만 표현을 해주시는것이 좋습니다.

그런데 여기서 m은 무엇을 나타낸건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dev-jonghoonpark

m 은 nums 배열에서 unique한 숫자 개수를 표현했습니다.
ex) nums : [1, 1, 1, 2, 2, 3] -> m = 3

최악의 경우 n*logn 이 되기 때문에 주석 수정해서 다시 커밋했습니다.

감사합니다. 👍

@heozeop heozeop self-requested a review August 16, 2024 02:35
Comment on lines +9 to +11
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>(
(a, b) -> Integer.compare(b.getValue(), a.getValue())
);
Copy link
Contributor

@taekwon-dev taekwon-dev Aug 17, 2024

Choose a reason for hiding this comment

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

저는 Map.Entry를 ArrayList를 사용하고 정렬을 했는데, PriorityQueue 사용하니까

  • Map.Entry 를 insert 하는데 더 효율적으로 할 수 있겠네요! (다뤄야 하는 Map.Entry가 많을수록 더 유리)
    • ArrayList의 insert는 O(N), PrioirtyQueue의 insert는 O(log N)
  • 다뤄야 하는 데이터가 많고 정렬해야 할 때 PrioirtyQueue 사용해봐야겠어요! 👍
  • (그리고 훨씬 간결하네요 ㅎㅎ)

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.

@f-exuan21 1주차 답안 제출이 얼마 남지 않았는데, 아직 PR이 Draft 상태이네요. 4문제만 푸셔도 충분히 잘 하신 거라고 생각합니다. 가급적 모임 전까지 Draft 해지 및 PR 병합 부탁드리겠습니다.

@heozeop heozeop removed their request for review August 18, 2024 03:02
@f-exuan21 f-exuan21 marked this pull request as ready for review August 19, 2024 09:49
@DaleSeo
Copy link
Member

DaleSeo commented Aug 19, 2024

@f-exuan21 linelint 검사가 실행될 수 있도록, 디폴트 브랜치를 rebase 하신 후에 force push 부탁드립니다. 그러면 PR도 머지하실 수 있으실 거에요.

f-exuan21 and others added 8 commits August 19, 2024 19:52
number of 1 bits solutions
Top K Frequent Elements Solutions
시간복잡도 공간복잡도 수정
HashSet -> Set 수정
kth-smallest-element-in-a-bst solution
주석 오타 수정
@f-exuan21 f-exuan21 merged commit cafbe96 into DaleStudy:main Aug 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

5 participants