프로그래머스
위장
끝까지 처음처럼
2022. 9. 27. 14:12
728x90
class Solution {
fun solution(clothes: Array<Array<String>>): Int {
var answer = 1
var clothSet = mutableMapOf<String,Int>()
for(cloth in clothes){
if(clothSet.containsKey(cloth[1])){ //해당 부위가 이미 등록되어 있을 경우
clothSet.put(cloth[1],clothSet.get(cloth[1])!!.plus(1))
} else {
clothSet.put(cloth[1], 1)
}
}
for(i in clothSet){
answer *= i.value + 1
}
return answer - 1
}
}
해당 문제는 작성하기에 앞서 잘 생각해보니 모든 경우의 수에서 모든것을 착용하지 않은 경우만 빼주면 되는 것이 아닌가? 라는 생각이 들어 LV2문제 답지 않게 금방 풀었던 문제 였던 것 같습니다.