Skip to content

Commit 8f9d34b

Browse files
committed
[level 1] Title: K번째수, Time: 2.85 ms, Memory: 81.7 MB -BaekjoonHub
1 parent a82fa4f commit 8f9d34b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

프로그래머스/1/42748. K번째수/K번째수.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
class Solution {
44
public int[] solution(int[] array, int[][] commands) {
5-
int[] answer=new int[commands.length];
6-
7-
for(int i=0;i< commands.length;i++){
8-
int[] temp=Arrays.copyOfRange(array,commands[i][0]-1,commands[i][1]);
9-
Arrays.sort(temp); // 2 3 5 6
10-
answer[i]=temp[commands[i][2]-1];
5+
ArrayList<Integer> answer = new ArrayList<>();
6+
for(int[] command : commands){
7+
int start = command[0];
8+
int end = command[1];
9+
int idx = command[2];
10+
ArrayList<Integer> list = new ArrayList<>();
11+
12+
for(int i = start-1; i < end; i++){
13+
list.add(array[i]);
14+
}
15+
Collections.sort(list);
16+
answer.add(list.get(idx-1));
1117
}
12-
return answer;
18+
19+
return answer.stream().mapToInt(Integer::intValue).toArray();
1320
}
1421
}

프로그래머스/1/42748. K번째수/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 77.3 MB, 시간: 0.50 ms
7+
메모리: 81.7 MB, 시간: 2.85 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 01월 02일 21:43:19
19+
2025년 09월 02일 18:04:35
2020

2121
### 문제 설명
2222

0 commit comments

Comments
 (0)