Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발 일기장

[프로그래머스] 해시-위장 문제 본문

프로그래머스 코딩테스트

[프로그래머스] 해시-위장 문제

enow 2020. 7. 20. 00:09
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;
    }
}

제가 푼 방식입니다. 참고하실분은 참고하세요!

Comments