[programmers] 위장

KwonSC·2022년 2월 28일
0

programmers - Java

목록 보기
3/17
post-thumbnail

https://programmers.co.kr/learn/courses/30/lessons/42578


Code

import java.util.*;
class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        Map<String, Integer> map = new HashMap<>();
        for (String[] cloth : clothes) {
            if (map.containsKey(cloth[1])) {
                map.put(cloth[1], map.get(cloth[1]) + 1);
            }
            else {
                map.put(cloth[1], 1);
            }
        }
        for (String key : map.keySet()) {
            answer *= (map.get(key) + 1);
        }
        return answer - 1;
    }
}

Solution

의상의 종류, 개수를 갖는 HashMap을 만들고 각 의상의 개수 + 1(그 옷을 안입은 경우)만큼 곱하고 1을 뺀다(모든 옷을 안입은 경우 1가지)

0개의 댓글

관련 채용 정보