Skip to content

회의실 배정#109

Merged
github-actions[bot] merged 1 commit into
mainfrom
liv
Mar 31, 2026
Merged

회의실 배정#109
github-actions[bot] merged 1 commit into
mainfrom
liv

Conversation

@sangYuLv
Copy link
Copy Markdown
Collaborator

🔗 문제 링크

✔️ 소요된 시간

35분

⏰ 시간 복잡도

O(n log n)

@sangYuLv sangYuLv self-assigned this Mar 31, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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)] = []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

입력받을 회의의 개수(meetingCount)를 미리 알고 있으므로, reserveCapacity(_:)를 사용하여 배열의 용량을 예약하면 배열 확장 시 발생하는 불필요한 메모리 재할당을 방지할 수 있습니다. $N$이 최대 100,000으로 큰 경우 성능 최적화에 도움이 됩니다.

Suggested change
var meetings: [(Int, Int)] = []
var meetings: [(Int, Int)] = []
meetings.reserveCapacity(meetingCount)

Comment on lines +7 to +8
let line = readLine()!.split(separator: " ").compactMap { Int($0) }
meetings.append((line[0], line[1]))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

루프 내부에서 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])!))

@github-actions github-actions Bot merged commit be63059 into main Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant