티스토리 뷰

PS/programmers

Level2) 위장

kingsubin 2021. 5. 3. 17:54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;
 
public class Level2_위장 {
    public static int solution(String[][] clothes) {
        Map<String, Integer> map = new HashMap<>();
 
        for (String[] str: clothes) {
            String key = str[1];
            map.put(key, map.getOrDefault(key, 0+ 1);
        }
 
        int answer = 1;
        for (int value : map.values()) {
            answer *= (value + 1);
        }
 
        return answer - 1;
    }
 
    public static void main(String[] args) {
        String[][] clotehs = {{"yellow_hat""headgear"}, {"blue_sunglasses""eyewear"}, {"green_turban""headgear"}};
        System.out.println(solution(clotehs));
    }
}
 
cs

'PS > programmers' 카테고리의 다른 글

Level2) 카펫  (0) 2021.07.13
Level2) H-Index  (0) 2021.05.04
Level1) 내적  (0) 2021.05.02
Level1) 폰켓몬  (0) 2021.05.01
Level1) 소수구하기  (0) 2021.04.30