회의실 배정#109
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements a greedy algorithm to solve the meeting room assignment problem in Swift. The code correctly sorts meetings by end time and then start time to maximize the count. The review feedback focuses on performance optimizations for large input sizes, specifically by pre-allocating array capacity and reducing memory overhead during input parsing.
| // 백준 - 1931 회의실 배정 | ||
|
|
||
| let meetingCount = Int(readLine()!)! | ||
| var meetings: [(Int, Int)] = [] |
Contributor
There was a problem hiding this comment.
Comment on lines
+7
to
+8
| let line = readLine()!.split(separator: " ").compactMap { Int($0) } | ||
| meetings.append((line[0], line[1])) |
Contributor
There was a problem hiding this comment.
루프 내부에서 compactMap을 사용하면 매 반복마다 새로운 [Int] 배열이 생성되어 메모리 할당 오버헤드가 발생합니다. 입력 형식이 보장되는 상황이라면 split 결과인 Substring 배열의 인덱스에 직접 접근하여 Int로 변환하는 것이 더 효율적입니다.
Suggested change
| let line = readLine()!.split(separator: " ").compactMap { Int($0) } | |
| meetings.append((line[0], line[1])) | |
| let line = readLine()!.split(separator: " ") | |
| meetings.append((Int(line[0])!, Int(line[1])!)) |
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.
🔗 문제 링크
✔️ 소요된 시간
35분
⏰ 시간 복잡도
O(n log n)