본문 바로가기
알고리즘

[Java]프로그래머스 위장

by irerin07 2019. 4. 15.
728x90

```

import java.util.*;
class Solution {
    public int solution(String[][] clothes) {
       int answer = 0;
HashMap<String, Integer> hm = new HashMap<String, Integer>();

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

int tempans = 1;
for(int a: hm.values()) {
tempans *=  a + 1;
}
answer = tempans - 1;
return answer;
    }
}

```

 

문제를 잘 이해하지 못해서 초반에 고생 한 문제

문제만 잘 이해하면 그렇게 어려운 문제가 아니다

728x90

'알고리즘' 카테고리의 다른 글

[Java]프로그래머스 더 맵게  (0) 2019.04.24
[Java]프로그래머스 카펫  (0) 2019.04.15
[Java]프로그래머스 쇠막대기  (0) 2019.04.15
[Java]프로그래머스 프린터  (0) 2019.04.15
[Java]프로그래머스 스킬트리  (0) 2019.04.15