Skip to content

Commit 216f8ba

Browse files
committed
[level 1] Title: K번째수, Time: 0.52 ms, Memory: 86.4 MB -BaekjoonHub
1 parent dca3e63 commit 216f8ba

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] solution(int[] array, int[][] commands) {
5+
int num = commands.length;
6+
int[] answer = new int[num];
7+
8+
for (int i = 0; i < num; i++) {
9+
int from = commands[i][0];
10+
int to = commands[i][1];
11+
int index = commands[i][2];
12+
13+
int[] temp = new int[to - from + 1];
14+
for (int j = 0; j < temp.length; j++) {
15+
temp[j] = array[from - 1 + j];
16+
}
17+
18+
Arrays.sort(temp);
19+
20+
answer[i] = temp[index - 1];
21+
}
22+
return answer;
23+
}
24+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# [level 1] K번째수 - 42748
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/42748)
4+
5+
### 성능 요약
6+
7+
메모리: 86.4 MB, 시간: 0.52 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 정렬
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 08월 25일 23:38:48
20+
21+
### 문제 설명
22+
23+
<p>배열 array의 i번째 숫자부터 j번째 숫자까지 자르고 정렬했을 때, k번째에 있는 수를 구하려 합니다.</p>
24+
25+
<p>예를 들어 array가 [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3이라면</p>
26+
27+
<ol>
28+
<li>array의 2번째부터 5번째까지 자르면 [5, 2, 6, 3]입니다.</li>
29+
<li>1에서 나온 배열을 정렬하면 [2, 3, 5, 6]입니다.</li>
30+
<li>2에서 나온 배열의 3번째 숫자는 5입니다.</li>
31+
</ol>
32+
33+
<p>배열 array, [i, j, k]를 원소로 가진 2차원 배열 commands가 매개변수로 주어질 때, commands의 모든 원소에 대해 앞서 설명한 연산을 적용했을 때 나온 결과를 배열에 담아 return 하도록 solution 함수를 작성해주세요.</p>
34+
35+
<h5>제한사항</h5>
36+
37+
<ul>
38+
<li>array의 길이는 1 이상 100 이하입니다.</li>
39+
<li>array의 각 원소는 1 이상 100 이하입니다.</li>
40+
<li>commands의 길이는 1 이상 50 이하입니다.</li>
41+
<li>commands의 각 원소는 길이가 3입니다.</li>
42+
</ul>
43+
44+
<h5>입출력 예</h5>
45+
<table class="table">
46+
<thead><tr>
47+
<th>array</th>
48+
<th>commands</th>
49+
<th>return</th>
50+
</tr>
51+
</thead>
52+
<tbody><tr>
53+
<td>[1, 5, 2, 6, 3, 7, 4]</td>
54+
<td>[[2, 5, 3], [4, 4, 1], [1, 7, 3]]</td>
55+
<td>[5, 6, 3]</td>
56+
</tr>
57+
</tbody>
58+
</table>
59+
<h5>입출력 예 설명</h5>
60+
61+
<p>[1, 5, 2, 6, 3, 7, 4]를 2번째부터 5번째까지 자른 후 정렬합니다. [2, 3, 5, 6]의 세 번째 숫자는 5입니다.<br>
62+
[1, 5, 2, 6, 3, 7, 4]를 4번째부터 4번째까지 자른 후 정렬합니다. [6]의 첫 번째 숫자는 6입니다.<br>
63+
[1, 5, 2, 6, 3, 7, 4]를 1번째부터 7번째까지 자릅니다. [1, 2, 3, 4, 5, 6, 7]의 세 번째 숫자는 3입니다.</p>
64+
65+
66+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges

0 commit comments

Comments
 (0)