[Cyjin-jani] WEEK 01 solutions#2369
Merged
Cyjin-jani merged 6 commits intoDaleStudy:mainfrom Mar 7, 2026
Merged
Conversation
doh6077
approved these changes
Mar 5, 2026
| tempArr[val].push(+key); | ||
| } | ||
|
|
||
| const answer = tempArr.flat(); |
Contributor
There was a problem hiding this comment.
안녕하세요 깔끔한 코드 잘 보았습니다!!
Suggested change
| const answer = tempArr.flat(); | |
| const answer = []; | |
| for (let i = tempArr.length - 1; i >= 0; i--) { | |
| for (let num of tempArr[i]) { | |
| answer.push(num); | |
| if (answer.length === k) return answer; | |
| } | |
| } | |
| return answer; |
flat() 를 사용하는 방식도 좋지만 전체 버킷을 모두 펼치는 대신에 tempArr를 뒤에서부터 순회하면서 answer 에 필요한 k개만 담아 바로 리턴하는 방식도 고려해보시면 좋을 것 같아요.
공간복잡도는 동일한 O(n) 이지만 k가 작은 경우에는 새 배열을 추가로 생성하기보다는 k개의 개수만 모아서 반환하는 방식이 효율적일 수도 있을거 같네요.
Contributor
Author
There was a problem hiding this comment.
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로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!