[JisooPyo] Week 1#643
Merged
JisooPyo merged 5 commits intoDaleStudy:mainfrom Dec 9, 2024
JisooPyo:main
Merged
Conversation
EgonD3V
approved these changes
Dec 7, 2024
Contributor
EgonD3V
left a comment
There was a problem hiding this comment.
전반적으로 시간복잡도와 공간복잡도를 이해하기 쉽게 분석해주시고, 또한 개선점을 추가해서 풀어주셔서 좋았습니다.
| * 개선된 버전: 우선순위 큐를 사용 | ||
| * | ||
| * Runtime: 19 ms(Beats: 96.30 %) | ||
| * Time Complexity: O(n log n) |
Contributor
There was a problem hiding this comment.
PriorityQueue에 n개를 삽입하고 k개를 꺼냈으니 O(n log k)가 맞지 않을까요?
Member
Author
There was a problem hiding this comment.
@EgonD3V 리뷰 감사합니다!
- k개를 꺼내기 전 PriorityQueue에 값들을 삽입 연산을 생각해보면,
- nums에서 고유한 값의 개수가 m개라고 가정합니다.
- offer()의 시간복잡도는 O(log m), 따라서 m개를 삽입하니 O(m log m) 의 시간복잡도로 계산할 수 있습니다.
- k개의 요소를 추출할 때의 시간 복잡도를 생각해보면,
- 각 추출 연산 역시 O(log m)이 되며, k번 수행하게 되므로 O(k log m)이 됩니다.
따라서 전체 시간 복잡도는
- 배열 순회, 그룹화: O(n)
- 우선순위 큐 연산: O(m log m + k log m)
- 최종: O(n + m log m)
여기서 m은 최대 n이 될 수 있으므로 O(n log n)이 됩니다!
Member
Author
There was a problem hiding this comment.
아! PriorityQueue의 크기를 k로 제한하면 O(n log k)로 더 최적화 할 수 있겠네요..!
DaleSeo
approved these changes
Dec 8, 2024
| var currentNum = num | ||
| var currentLength = 0 | ||
|
|
||
| while (numsSet.contains(currentNum)) { |
Member
There was a problem hiding this comment.
요렇게 하면 currentNum 변수를 사용할 필요가 없어져서 코드가 더 간단해지지 않을까 생각해보았습니다. (안 중요)
Suggested change
| while (numsSet.contains(currentNum)) { | |
| while (numsSet.contains(num + currentLength)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
체크 리스트
In Review로 설정해주세요.