Skip to content

[jinho] Week 1 #632

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 3 commits into from
Dec 13, 2024
Merged

[jinho] Week 1 #632

merged 3 commits into from
Dec 13, 2024

Conversation

neverlish
Copy link
Contributor

@neverlish neverlish commented Dec 4, 2024

답안 제출 문제

체크 리스트

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

@neverlish neverlish requested a review from a team as a code owner December 4, 2024 16:14
@github-actions github-actions bot added the go label Dec 4, 2024
@neverlish neverlish requested a review from dalpang81 December 4, 2024 16:15
Comment on lines 20 to 38
freq_by_counts := make(map[int][]int)

for num, count := range freq {
if _, ok := freq_by_counts[count]; !ok {
freq_by_counts[count] = []int{}
}
freq_by_counts[count] = append(freq_by_counts[count], num)
}

result := []int{}

for count := len(nums); count > 0; count-- {
if nums, ok := freq_by_counts[count]; ok {
if len(result) >= k {
break
}
result = append(result, nums...)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

문제의 조건을 잘 이용한 풀이라고 생각합니다 :)
It is guaranteed that the answer is unique.

freq_by_counts[count] = append(freq_by_counts[count], num)
}

result := []int{}
Copy link
Contributor

@obzva obzva Dec 5, 2024

Choose a reason for hiding this comment

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

result slice를 선언할 때 make를 이용해서 capacity나 length를 설정해주는 것이 더 효율적일 것 같습니다
k가 커지면 re-allocation에 소모되는 연산량이 많을 수도 있을 것 같아요

Suggested change
result := []int{}
result := make([]int, k) // Or, result := make([]int, 0, k)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

487db4c 요렇게 작성해보았습니다

Copy link
Contributor

@obzva obzva left a comment

Choose a reason for hiding this comment

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

깔끔한 풀이 잘 보았습니다 :)
Big O 분석을 남겨주시는 것이 좋을 것 같습니다
알고리즘 면접 시에 본인 풀이의 시공간 복잡도를 파악하는 것은 알고리즘의 효율성을 파악하는 중요한 척도가 되며, 면접관들과 이야기할 때도 주요한 수단이 되기 때문입니다
또한 시공간 복잡도를 분석함으로써 기존의 풀이를 어떻게 하면 더 최적화시킬 수 있는지에 대해 고민해볼 수도 있습니다

@neverlish
Copy link
Contributor Author

피드백 감사합니다!
73af29d 에서, 시간/공간 복잡도를 간단히 남겨보았습니다

@neverlish neverlish requested a review from obzva December 5, 2024 10:01
@dalpang81
Copy link
Contributor

풀이 잘 보았습니다..! 제가 go언어는 처음봐서 좀 더 유심히 보고 분석하느라 재밋었습니다! 아직은 코드가 익숙하지않아서 좋은 공부시간이였던 것 같습니다 수고하셨어요!

@neverlish neverlish merged commit 15c1278 into DaleStudy:main Dec 13, 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.

3 participants