-Code
class Solution {
public String solution(String[] storage, int[] num) {
int num_item = 0;
String[] clean_storage = new String[storage.length];
int[] clean_num = new int[num.length];
for(int i=0; i<storage.length; i++){
int clean_idx = -1;
for(int j=0; j<num_item; j++){
if(storage[i].equals(clean_storage[j])){
clean_idx = j;
break;
}
}
if(clean_idx == -1){
clean_storage[num_item] = storage[i];
clean_num[num_item] = num[i];
num_item += 1;
}
else{
clean_num[clean_idx] += num[i];
}
}
// 아래 코드에는 틀린 부분이 없습니다.
int num_max = -1;
String answer = "";
for(int i=0; i<num_item; i++){
if(clean_num[i] > num_max){
num_max = clean_num[i];
answer = clean_storage[i];
}
}
return answer;
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 약수의 합 (0) | 2025.02.23 |
---|---|
[프로그래머스/Java] 문자열을 정수로 바꾸기 (1) | 2025.02.23 |
[프로그래머스/Java] [PCCE 기출문제] 8번 / 닉네임 규칙 (1) | 2025.02.22 |
[백준/파이썬] 24349번 МЕД (0) | 2025.02.22 |
[프로그래머스/Java] [PCCE 기출문제] 7번 / 버스 (0) | 2025.02.22 |