[프로그래머스] 위장-해시 Level2 (자바,java)

[프로그래머스] 위장-해시 Level2 (자바,java)

- 풀이

처음에는 백트래킹하여 모든 경우의수를 구해야되나 싶었는데

그냥 수학적으로 경우의수를 구하는 공식이 있었다.

import java.util.HashMap; class Solution { public static int solution(String[][] clothes) { int answer = 1; HashMap map = new HashMap<>(); for (int i=0; i< clothes.length; i++) { map.put(clothes[i][1],map.getOrDefault(clothes[i][1],0)+1); } for (int x : map.values()) { answer*=(x+1); } return answer-1; } }

해시맵에 아직 미숙한거같다.. 많이 사용해보도록 하자

from http://rotomoo.tistory.com/21 by ccl(A) rewrite - 2021-11-02 12:27:11