-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Milestone
Description
func solution(_ N:Int, _ stages:[Int]) -> [Int] {
// 플레이어 총 인원수
var player = stages.count
// �<스테이지 번호, 실패율>
var stageRateDic: Dictionary<Int, Double> = [:]
for i in 1 ... N {
let stayPlyer = stages.filter{ $0 == i } // i번째 stage에 있는 플레이어 수 = stayPlyer.count
let rate = Double(stayPlyer.count) / Double(player)
stageRateDic[i] = rate
player -= stayPlyer.count // 총 인원수에서 i번째 스테이지에 머물러 있는 플레이어 빼기
}
// stageRateDic을 value(실패율) 기준으로 정렬하되, 값이 같으면 key(스테이지번호) 기준 정렬
let sortedDic = stageRateDic.sorted {
if $0.1 == $1.1 { return $0.0 > $1.0 }
return $0.1 < $1.1
}
// sortedDic의 key값만 배열에 담아서 return
var resultArray = [Int]()
for (key, _) in sortedDic.reversed() {
resultArray.append(key)
}
return resultArray
}실패 테스트 번호 : 1, 6, 7, 13, 23, 24, 25
시간초과 테스트 번호 : 5, 9
첫 번째 도전 실패했습니다!! 평일동안 다시 풀어서 업데이트 하겠습니다👍