[프로그래머스] [LV2] 위장
업데이트:
📚 위장
링크📎 : https://programmers.co.kr/learn/courses/30/lessons/42578?language=java#
난이도 ⭐️⭐️
📖 문제
📝 내 풀이
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int i = 0; i < clothes.length; i++){
if(!map.containsKey(clothes[i][1])) map.put(clothes[i][1], 1);
else map.put(clothes[i][1], map.get(clothes[i][1])+1);
}
for(String key : map.keySet())
answer *= (map.get(key)+1);
return answer-1;
}
}
👊🏻 전략
- 조합의 수를 생각하자 ex) 4종류일 경우 = (종류1+1)x(종류2+1)x(종류3+1)x(종류4+1) - 1
- 조합을 Hash의 key-value로 관리하자
끝-!
댓글남기기