알고리즘 풀이/프로그래머스

[프로그래머스][Java] 위장

배게 2019. 4. 3. 14:11
728x90

(a,b,c) - (e,f)의 조합을


(0,a,b,c) - (0,e,f)의 식으로 가상의 0개를 생성해주어 곱한 후에


옷을 하나도 안입는 경우인 (0) - (0)만 빼주는 생각을


참고 안했으면 절대 못풀었을 것임


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;

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

        for(int i=0; i<clothes.length; i++){
            if(!hm.containsKey(clothes[i][1])) hm.put(clothes[i][1],1);
            else hm.put(clothes[i][1], hm.get(clothes[i][1])+1);
        }

        int answer=1;
        for(Integer i : hm.values()){
            answer *= i+1;
            System.out.println(i);
        }
        System.out.println(answer);

        return answer-1;
    }
}



참고 : https://tallman.tistory.com/7