본문 바로가기
끄적/Java_CT

자바 코테 HashMap 활용

by 밀키스 2021. 7. 13.

 

import java.util.HashMap;
class Solution {
    public int[] solution(String[] genres, int[] plays) {
        HashMap<String, Integer> music = new HashMap<String, Integer>();
        HashMap<String, Integer> music_cnt = new HashMap<String, Integer>();
        HashMap<String, Integer> music_idx = new HashMap<String, Integer>();
        HashMap<String, Integer> music_num = new HashMap<String, Integer>();
        int len = 0;
        int knd = 0;
        String[] knd_l = new String[genres.length];
        for(int i=0;i<genres.length;i++){
            if(music.get(genres[i]) == null){
                music.put(genres[i], plays[i]);
                knd++;
                knd_l[i] = genres[i];
            }else{
                music.put(genres[i], music.get(genres[i]) + plays[i]);
            }
            if(music_cnt.get(genres[i])==null){
                music_cnt.put(genres[i], 1);
                len++;
            }else if(music_cnt.get(genres[i]) == 1){
                music_cnt.put(genres[i], 2);
                len++;
            }
        }
        int[] answer = new int[len];
        System.out.println(music);
        return answer;
    }
}

 

 

 

 

반응형

댓글