일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 백준 2252 줄세우기
- ipfs singletone
- java 1238
- rabbitmq 싱글톤
- kotiln const
- Spring ipfs
- spring mongodb switch
- java 팩토리얼 개수
- javav 1676
- Java Call By Refernce
- java 파티
- spring mongoTemplate
- nodejs rabbitmq
- 안정해시
- kotiln const val
- spring mongoTemplate switch
- kotiln functional interface
- 익명 객체 @transactional
- 자바 1676
- Claude Intelij 연결
- mongodb lookup
- spring mongodb
- ipfs bean
- java 1509
- java 백준 1509
- 자바 백준 팩토리얼 개수
- 백준 특정한 최단 경로
- 백준 연결요소 자바
- 백준 1504 java
- go
Archives
- Today
- Total
공부 흔적남기기
프로그래머스 K번째수 본문
728x90
반응형
import java.util.ArrayList;
import java.util.Collections;
class Solution {
public int[] solution(int[] array, int[][] commands) {
//각 command 마다 하나의 결과 값이 나오므로 commands의 길이의 배열 만듦
int[] answer = new int[commands.length];
ArrayList<Integer> arrayList = new ArrayList<>();
//
for(int i =0; i<commands.length; i++){
//command의 각 숫자들을 저장
int x = commands[i][0];
int j = commands[i][1];
int k = commands[i][2];
arrayList.clear();
// x부터 j까지 배열을 자름
for(int l =x-1; l<j; l++ ){
arrayList.add(array[l]);
}
//자른 배열을 정렬시킴
Collections.sort(arrayList);
//k번쨰에 있는 수를 answer에 저장시킴
answer[i] = arrayList.get(k-1);
}
return answer;
}
}
출처: 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
728x90
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 소수찾기 (0) | 2022.01.16 |
---|---|
프로그래머스 나머지가 1이 되는 수 찾기 (0) | 2022.01.16 |
프로그래머스 최대공약수와 최소공배수 (0) | 2022.01.16 |
프로그래머스 예산 (0) | 2022.01.16 |
프로그래머스 약수의 합 (0) | 2022.01.16 |