Skip to content

[JisooPyo] Week 1 #643

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 5 commits into from
Dec 9, 2024
Merged

[JisooPyo] Week 1 #643

merged 5 commits into from
Dec 9, 2024

Conversation

JisooPyo
Copy link
Member

@JisooPyo JisooPyo commented Dec 7, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@JisooPyo JisooPyo added the kotlin label Dec 7, 2024
@JisooPyo JisooPyo self-assigned this Dec 7, 2024
@JisooPyo JisooPyo requested a review from a team as a code owner December 7, 2024 05:31
@JisooPyo JisooPyo requested a review from oyeong011 December 7, 2024 05:35
Copy link
Contributor

@EgonD3V EgonD3V left a comment

Choose a reason for hiding this comment

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

전반적으로 시간복잡도와 공간복잡도를 이해하기 쉽게 분석해주시고, 또한 개선점을 추가해서 풀어주셔서 좋았습니다.

* 개선된 버전: 우선순위 큐를 사용
*
* Runtime: 19 ms(Beats: 96.30 %)
* Time Complexity: O(n log n)
Copy link
Contributor

Choose a reason for hiding this comment

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

PriorityQueue에 n개를 삽입하고 k개를 꺼냈으니 O(n log k)가 맞지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

@EgonD3V 리뷰 감사합니다!

  1. k개를 꺼내기 전 PriorityQueue에 값들을 삽입 연산을 생각해보면,
    • nums에서 고유한 값의 개수가 m개라고 가정합니다.
    • offer()의 시간복잡도는 O(log m), 따라서 m개를 삽입하니 O(m log m) 의 시간복잡도로 계산할 수 있습니다.
  2. 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)이 됩니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

아! PriorityQueue의 크기를 k로 제한하면 O(n log k)로 더 최적화 할 수 있겠네요..!

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.

@JisooPyo 님의 답안 코드에서 알고리즘 고수의 향기를 느끼고 갑니다 :) 멋진 활동 부탁드립니다!

var currentNum = num
var currentLength = 0

while (numsSet.contains(currentNum)) {
Copy link
Member

@DaleSeo DaleSeo Dec 8, 2024

Choose a reason for hiding this comment

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

요렇게 하면 currentNum 변수를 사용할 필요가 없어져서 코드가 더 간단해지지 않을까 생각해보았습니다. (안 중요)

Suggested change
while (numsSet.contains(currentNum)) {
while (numsSet.contains(num + currentLength)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

@DaleSeo 오 그렇네요! 리뷰 감사합니다!!

(ps. 안 중요 -> 중요)

@JisooPyo JisooPyo merged commit 9a149b9 into DaleStudy:main Dec 9, 2024
3 checks 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.

3 participants