STUDYING/Algorithm

[Programmers] 위장

EOZIN 2021. 9. 27. 00:41
728x90
func solution(_ clothes:[[String]]) -> Int {
    
    var dic: [String: Int] = [:]
    
    clothes.forEach { (cloth) in
        if dic.keys.contains(cloth[1]) {
            dic[cloth[1]]! += 1
        } else {
            dic[cloth[1]] = 1
        }
    }
    
    var result = 1
    for val in dic {
        result *= (val.value + 1)
    }
    
    return result - 1
}