-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[프로그래머스 스쿨 - 온라인 IT 특화 교육 전문 플랫폼](https://school.programmers.co.kr/learn/courses/30/parts/12077)
💬 Idea
- Dictionary로 옷의 종류별 개수를 저장한 뒤 조합될 수 있는 수를 구하는 수식을 잘 생각하면 쉬웠던 문제였다.
- 그런데 수로 접근하지 않고, 모든 조합의 경우를 String으로 반환하려 해서 조금 헤매었다.
💬 풀이
func solution(_ clothes:[[String]]) -> Int {
var clothesDict: [String: Int] = [:]
for cloth in clothes {
if clothesDict[cloth[1]] != nil {
clothesDict[cloth[1]]! += 1
} else {
clothesDict[cloth[1]] = 1
}
}
var result = 1
for i in clothesDict.values {
result *= (i+1)
}
return result - 1
}