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;
}
}
반응형
'끄적 > Java_CT' 카테고리의 다른 글
[자바 코테]백준 1756번 피자굽기 (0) | 2022.03.12 |
---|---|
[자바 코테] startsWith / 람다식 사용하기 (0) | 2021.11.21 |
[자바 코테] Math.max/min 활용하기 (0) | 2021.09.28 |
[자바 코테] matches 활용 (0) | 2021.08.31 |
자바 코테 replaceAll 활용 (0) | 2021.07.09 |
댓글