File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 22
33class 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}
Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 77.3 MB, 시간: 0.50 ms
7+ 메모리: 81.7 MB, 시간: 2.85 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 01월 02일 21:43:19
19+ 2025년 09월 02일 18:04:35
2020
2121### 문제 설명
2222
You can’t perform that action at this time.
0 commit comments