개발 일기장
[프로그래머스] 해시-위장 문제 본문
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
class Solution {
public int solution(String[][] clothes) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int i=0; i<clothes.length ;i++) {
for(int j=0; j<2 ;j++) {
if(j==1) {
map.put(clothes[i][j], map.getOrDefault(clothes[i][j],0)+1);
}
}
}
Set<String> set = map.keySet();
Iterator<String> it = set.iterator();
int sum = map.get(it.next());
while(it.hasNext()) {
int i=map.get(it.next());
sum = (sum+1)*i+sum;
}
return sum;
}
}
제가 푼 방식입니다. 참고하실분은 참고하세요!
'프로그래머스 코딩테스트' 카테고리의 다른 글
[프로그래머스]스택/큐 - 트럭문제 (0) | 2020.07.20 |
---|---|
[프로그래머스] 스택/큐 - 탑 문제 (0) | 2020.07.20 |
[프로그래머스] 해쉬-베스트 엘범 문제 (0) | 2020.07.20 |