-
-
Notifications
You must be signed in to change notification settings - Fork 303
[samcho0608] WEEK 01 solutions #1995
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
| for(int num : nums) { | ||
| if(!uniqNums.add(num)) return true; | ||
| } |
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.
저는 set 내 값 체크 유무를 contains() 메소드를 주로 떠올리는데,
HashSet의 add() 메소드 리턴 값을 이용하신 부분에서 인상깊었습니다.
|
Great job on submitting multiple solutions across different problems! Your code is clear, well-commented, and demonstrates good understanding of the algorithms. Here are some constructive suggestions to further improve your work:
Overall, your solutions are solid, and with some refinements, they can be even more efficient and easier to follow. Keep up the excellent work — your understanding of these algorithms is evident, and your consistent commenting shows good coding practices. |
|
|
||
| // count till end of consecutive sequence | ||
| int len = 1; | ||
| for(int i = 1; uniq.contains(num + i); 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.
해당 부분에서 i 값이 따로 쓰이지 않아서 while문으로 작성하는 것도 나쁘지 않을 것 같습니다.
while(uniq.contains(num + i)) {
len++;
}
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.
조건문이 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.
아 그렇네요! 주의깊게 살폈어야 했는데, 말씀 주신 부분을 미처 고려하지 못했네요. 앞으로는 더 꼼꼼히 확인하도록 하겠습니다.
| PriorityQueue<int[]> heap = new PriorityQueue<>(Comparator.comparingInt(a -> a[1])); | ||
| for(int num : freq.keySet()) { | ||
| int f = freq.get(num); // O(1) | ||
| heap.add(new int[]{num, f}); // O(log k) | ||
|
|
||
| if(heap.size() > k) heap.poll(); // O(log k) | ||
| } |
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.
PriorityQueue 내 요소 개수를 k개로 유지해서, O(NlogN)이 아닌 O(Nlogk)로 하신 방법이 흥미롭네요.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!