Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[프로그래머스] Lv. 2 의상 [Python, Java] 본문
- 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/42578
- 딕셔너리, 해시 맵
파이썬
def solution(clothes):
answer = 1
dic = {}
for li in clothes:
dic[li[1]] = dic.get(li[1], 1) + 1
for key in dic:
answer *= dic[key]
return answer - 1
자바
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
Map<String, Integer> map = new HashMap<>();
for (String[] arr : clothes) {
map.put(arr[1], map.getOrDefault(arr[1], 0) + 1);
}
for (int i : map.values()) {
answer *= i + 1;
}
return answer-1;
}
}
'프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv.2 더 맵게 [Python, 파이썬] (0) | 2023.07.09 |
---|---|
[프로그래머스] Lv.2 프로세스 [Python, Java] (0) | 2023.07.02 |
[프로그래머스] Lv.1 완주하지 못한 선수 [Python, Java] (0) | 2023.06.29 |
[프로그래머스] Lv.1 폰켓몬 [Python, Java] (0) | 2023.06.29 |
[프로그래머스] Lv.3 양과 늑대 [Python, 파이썬] (0) | 2023.06.13 |
Comments