prgms.42578 - 위장

class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        Map<String, Integer> map = new HashMap<>();

        for (String[] clothe : clothes) {
            if (!map.containsKey(clothe[1])) {
                map.put(clothe[1], 1);
            } else {
                map.put(clothe[1], map.get(clothe[1]) + 1);
            }
        }

        for (String key : map.keySet()) {
            answer *= (map.get(key) + 1);
        }

        return answer - 1;
    }
}
import java.util.*;
import static java.util.stream.Collectors.*;

class Solution {
    public int solution(String[][] clothes) {
        return Arrays.stream(clothes)
                .collect(groupingBy(p -> p[1], mapping(p -> p[0], counting())))
                .values()
                .stream()
                .collect(reducing(1L, (x, y) -> x * (y + 1))).intValue() - 1;
    }
}
import java.util.Collection;
import java.util.HashMap;

class Solution {
 public int solution(String[][] clothes) {
    var map = new HashMap<String, Integer>();
    for (String[] strings : clothes) {
      int p = 0;
      String key = strings[1];
      if(map.containsKey(key)){
        p = map.get(key);
      }
      map.put(key, p+1);
    }
    Collection<Integer> values = map.values();
    Integer[] counts = new Integer[values.size()];
    values.toArray(counts);

    int[][] dp = new int[values.size()][2];
    dp[0][0] = 1;
    dp[0][1] = counts[0];
    for (int i = 1; i < dp.length; i++) {
      dp[i][0] = dp[i-1][0] + dp[i-1][1];
      dp[i][1] = dp[i-1][0] * counts[i] + dp[i-1][1] * counts[i];
    }

    return dp[dp.length-1][0] + dp[dp.length-1][1] -1;
  } 
}

https://velog.io/@giraffelim/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%9C%84%EC%9E%A5