From 3bba0e6fd08858c312a446dc2405022e8efcf6f2 Mon Sep 17 00:00:00 2001 From: rl544 <111494264+rl544@users.noreply.github.com> Date: Thu, 1 Dec 2022 16:26:06 +0900 Subject: [PATCH] =?UTF-8?q?uploaded=20at=202022.=2012.=201.=20=EC=98=A4?= =?UTF-8?q?=ED=9B=84=204:26:05?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programmers/명예의 전당 (1)/solution.java | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 programmers/명예의 전당 (1)/solution.java diff --git a/programmers/명예의 전당 (1)/solution.java b/programmers/명예의 전당 (1)/solution.java new file mode 100644 index 0000000..e356f5d --- /dev/null +++ b/programmers/명예의 전당 (1)/solution.java @@ -0,0 +1,27 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/138477 + +import java.util.ArrayList; +import java.util.Collections; +class Solution { + public int[] solution(int k, int[] score) { + int[] answer2 = {}; + ArrayList answer = new ArrayList(); + ArrayList hall = new ArrayList(); + for(int i = 0; i < score.length; i++){ + if(i > k-1){ + if(score[i] > hall.get(0)){ + hall.add(score[i]); + hall.remove(hall.get(0)); + } + } + else hall.add(score[i]); + Collections.sort(hall); + answer.add(hall.get(0)); + } + answer2 = new int[answer.size()]; + for (int i = 0; i < answer.size(); i++) { + answer2[i] = answer.get(i); + } + return answer2; + } +} \ No newline at end of file