-Code
import java.util.*;
class Solution {
public int[] solution(int k, int[] score) {
List<Integer> honor = new ArrayList<>();
List<Integer> answer = new ArrayList<>();
for (int p : score) {
honor.add(p);
Collections.sort(honor);
if (honor.size() > k) {
honor.remove(0);
}
answer.add(honor.get(0));
}
return answer.stream().mapToInt(Integer::intValue).toArray();
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 카드 뭉치 (0) | 2025.02.26 |
---|---|
[프로그래머스/Java] [1차] 비밀지도 (0) | 2025.02.26 |
[프로그래머스/Java] 콜라 문제 (0) | 2025.02.26 |
[프로그래머스/Java] 문자열 내 마음대로 정렬하기 (0) | 2025.02.26 |
[프로그래머스/Java] 푸드 파이트 대회 (0) | 2025.02.26 |