위장

Updated:

BOJ의 패션왕 신해빈과 동일한 문제이다.

  1. 각 clothes에 해당하는 갯수를 세준다(ex) headgear 몇개, eyewear 몇개…)
  2. 그다음, 각원소의 갯수를 (a,b,c,…)이라 하면
  3. (a+1)(b+1)(c+1)… 를 한후에 1을 빼준값을 리턴하면 된다

by Java

import java.util.*;
class Solution {
    public int solution(String[][] clothes) {
        Map<String,Integer> map = new HashMap<>();
        for(int i=0;i<clothes.length;i++) {
            String s = clothes[i][1];
            if(map.get(s)==null) {
                map.put(s,1);
            }
            else {
                int value = map.get(s);
                value++;
                map.remove(s);
                map.put(s,value);
            }
        }
        int cnt=1;
        for(String e : map.keySet()) {
            cnt *= (map.get(e)+1);
        }
        return cnt-1;
    }
}

Leave a comment