-
-
Notifications
You must be signed in to change notification settings - Fork 195
[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
[jinho] Week 1 #632
Conversation
top-k-frequent-elements/neverlish.go
Outdated
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...) | ||
} | ||
} |
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.
문제의 조건을 잘 이용한 풀이라고 생각합니다 :)
It is guaranteed that the answer is unique.
top-k-frequent-elements/neverlish.go
Outdated
freq_by_counts[count] = append(freq_by_counts[count], num) | ||
} | ||
|
||
result := []int{} |
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.
result
slice를 선언할 때 make
를 이용해서 capacity나 length를 설정해주는 것이 더 효율적일 것 같습니다
k
가 커지면 re-allocation에 소모되는 연산량이 많을 수도 있을 것 같아요
result := []int{} | |
result := make([]int, k) // Or, result := make([]int, 0, 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.
487db4c 요렇게 작성해보았습니다
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.
깔끔한 풀이 잘 보았습니다 :)
Big O 분석을 남겨주시는 것이 좋을 것 같습니다
알고리즘 면접 시에 본인 풀이의 시공간 복잡도를 파악하는 것은 알고리즘의 효율성을 파악하는 중요한 척도가 되며, 면접관들과 이야기할 때도 주요한 수단이 되기 때문입니다
또한 시공간 복잡도를 분석함으로써 기존의 풀이를 어떻게 하면 더 최적화시킬 수 있는지에 대해 고민해볼 수도 있습니다
피드백 감사합니다! |
풀이 잘 보았습니다..! 제가 go언어는 처음봐서 좀 더 유심히 보고 분석하느라 재밋었습니다! 아직은 코드가 익숙하지않아서 좋은 공부시간이였던 것 같습니다 수고하셨어요! |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.