IT STUDY LOG
[JAVA] 프로그래머스: K번째수 본문
# 문제 내용
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
# 알고리즘 분류
- 정렬
# 풀이
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for (int i = 0; i < commands.length; i++) {
// commands[i][0] = 시작
// commands[i][1] = 끝
// commands[i][2] = 출력 숫자
int[] tmp = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
Arrays.sort(tmp);
answer[i] = tmp[commands[i][2]-1];
}
return answer;
}
}
'computer science > coding test' 카테고리의 다른 글
[JAVA] 프로그래머스: 최소직사각형 (0) | 2023.05.04 |
---|---|
[MySQL] 프로그래머스: 평균 일일 대여 요금 구하기 (0) | 2023.05.03 |
[Python] 백준 12865: 평범한 배낭 (0) | 2023.04.26 |
[MySQL] 프로그래머스: 12세 이하인 여자 환자 목록 출력하기 (0) | 2023.04.26 |
[JAVA] 프로그래머스: 더 맵게 (0) | 2023.04.26 |
Comments