STUDYING/Algorithm
[Programmers] 호텔 방 배정
EOZIN
2021. 9. 27. 00:42
728x90
https://programmers.co.kr/learn/courses/30/lessons/64063
import Foundation
var dict = [Int64: Int64]()
func solution(_ k: Int64, _ room_number: [Int64]) -> [Int64] {
var answer = [Int64]()
for number in room_number {
let room = find(room: number)
answer.append(room)
}
return answer
}
func find(room: Int64) -> Int64 {
if dict[room] == nil {
dict[room] = room + 1
return room
}
dict[room] = find(room: dict[room]!)
return dict[room]!
}