Swift랑 친해지기/programmers 풀기

[프로그래머스] 진료 순서 정하기 (Swift)

데브킹덕 2023. 1. 24. 15:06
import Foundation

func solution(_ emergency:[Int]) -> [Int] {
    let sortedEmergency = emergency.sorted(by:>)
    
    var dic : [Int : Int] = [:]
    var result = [Int]()
    
    for index in 0..<sortedEmergency.count{
        dic[sortedEmergency[index]] = index + 1
    }
    
    for num in emergency{
        result.append(dic[num]!)
    }
    return result
}