-
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문제 답지 않게 금방 풀었던 문제 였던 것 같습니다.
'프로그래머스' 카테고리의 다른 글
연속 부분 수열 합의 개수 (0) 2022.10.27 H-Index (0) 2022.09.27 n^2 배열 자르기 (0) 2022.09.27 기능개발 (0) 2022.09.27 프린터 (0) 2022.09.27