728x90
https://school.programmers.co.kr/learn/courses/30/lessons/258712
static int solution(String[] friends, String[] gifts) {
int answer = 0;
int num_fr = friends.length;
Map<String, Integer> map = new HashMap<>();
for(int i=0;i<num_fr;i++){
map.put(friends[i],i);
}
int[][] presents = new int[num_fr][num_fr];
int[] percentage = new int[num_fr];
for(String str : gifts){
int to = map.get(str.split(" ")[0]);
int from = map.get(str.split(" ")[1]);
presents[to][from] +=1;
percentage[to]+=1;
percentage[from]-=1;
}
for(int i=0;i<num_fr;i++){
int num=0;
for(int j=0;j<num_fr;j++){
if(i==j) continue;
if(presents[i][j] > presents[j][i] ||
(presents[i][j] == presents[j][i] && percentage[i]>percentage[j])){
num++;
}
}
answer= Math.max(answer,num);
}
return answer;
}
728x90
'🐣 알고리즘 삐약 > ✏️ 냅다 덤벼보는 문제풀이' 카테고리의 다른 글
[프로그래머스] 완주하지 못한 선수 | 해시 | lv.1 | JAVA (0) | 2024.10.31 |
---|---|
[프로그래머스] 폰켓몬 | 해시 | lv.1 | JAVA (0) | 2024.10.31 |
[프로그래머스] LV2. 택배 배달과 수거하기 | JAVA (0) | 2024.08.15 |
[프로그래머스] LV.1 개인정보 수집 유효기간 | JAVA (0) | 2024.08.15 |
[codeforces] Ebony and Ivory | Cpp (0) | 2022.05.24 |