이전 코드
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
HashMap<String, Integer> hm = new HashMap<>();
for (String [] item : clothes){
if(hm.get(item[1]) == null){
hm.put(item[1], 1);
} else {
hm.put(item[1], hm.get(item[1]) + 1);
}
}
for (int val : hm.values()){
answer *= (val+1);
}
return answer-1;
}
}
최근 코드
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
HashMap <String, Integer> map = new HashMap<>();
for (String [] wear : clothes){
map.put(wear[1], map.getOrDefault(wear[1], 1) + 1);
}
for (String key : map.keySet()){
answer *= map.get(key);
}
return answer - 1;
}
}
'프로그래머스 - JAVA' 카테고리의 다른 글
코딩테스트 연습 > 스택/큐 > 다리를 지나는 트럭 (0) | 2021.06.12 |
---|---|
코딩테스트 연습 > 스택/큐 > 프린터 (0) | 2021.06.12 |
코딩테스트 연습 > 스택/큐 > 기능개발 (0) | 2021.06.12 |
코딩테스트 연습 > 해시 > 베스트앨범 (0) | 2021.06.12 |
코딩테스트 연습 > 해시 > 전화번호 목록 (0) | 2021.06.12 |