🐣 알고리즘 삐약/✏️ 냅다 덤벼보는 문제풀이

[프로그래머스] 의상 | 해시 | lv.2 | JAVA

우주수첩 2024. 10. 31. 17:38
728x90

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

import java.util.*;
class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        Map<String,Integer> map = new HashMap<>();
        
        for(String[] arr : clothes){
            String cloth = arr[1];
            if(map.containsKey(cloth)){
               int count= map.get(cloth) +1;
                map.remove(cloth);
                map.put(cloth,count);
            }else{
                map.put(cloth,1);
            }
        }
        
        Iterator<Integer> iterator = map.values().iterator();
        
        
        while(iterator.hasNext()){
            answer *= iterator.next()+1;
        }
        
        return answer-1;
    }
}

 

 

 

 

아래와 풀이 거의 일치

2024.10.31 - [🐣 알고리즘 삐약/💻 백준 삐약] - 104 삐약 : 백준 9375 | 패션왕 신혜빈 [바킹독| HASH |JAVA]

 

 

 

 

728x90