일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- mysql
- springboot
- development
- Oracle11g
- RESTful
- oracle
- restapi
- Maven
- install
- 스프링부트 #springboot #project #Intellij
- mssql
- Developer
- 환경변수
- undefined
- ojdbc
- 웹개발
- Tomcat #SpringFramework
- IntelliJ
- 스프링시큐리티
- springboot #controller #jsp
- apache
- Database
- 스프링부트
- tcping
- HATEOAS
- Web
- SpringInitializer
- sqldeveloper
- SpringSecurity
- postman
Archives
- Today
- Total
여백에 도장 찍기
[Level1/정렬/K번째 수] 본문
https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
import java.util.Arrays;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for (int a=0; a<commands.length; a++) {
int i = commands[a][0]; // 시작
int j = commands[a][1]; // 끝
int k = commands[a][2]; // 출력을 원하는 위치
int[] temp = Arrays.copyOfRange(array, i-1, j);
Arrays.sort(temp);
answer[a] = temp[k-1];
}
return answer;
}
}
- Arrays.copyOfRange(원본 배열, 복사할 시작인덱스, 복사할 끝인덱스) -> 메서드를 통해 배열을 복사할 수 있다.
- 배열 정렬 : Arrays.sort();
- ArrayList 정렬: Collections.sort();
Comments