Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- JavaScript Obejct Notation
- 빗썸 API 사용
- 프로그래머스
- 즐겨찾기가 가장 많은 식당 정보 출력하기
- spring
- WAS란
- Web Server란
- JSON 형식
- Python
- 파이썬 주식
- 단순 반복 자동화
- java
- Web Service Architecture
- JSON특징
- 리눅스 777
- 리눅스
- pybithumb
- WAS WebServer 차이
- 트레이딩 봇 만들기
- beautifulsoup
- string format
- 오라클
- 와스 웹서버의 차이
- 파이썬
- 프로그래머스 SQL
- 파이썬 가상환경
- BigDecimal
- 리눅스 rwx
- 프로그래머스 소수
- 변동성 돌파전략
Archives
- Today
- Total
IT 개발자_S
[프로그래머스] k번째수 본문
반응형
1. 배열이 주어지고
2. 배열의 구간을 정해서 정렬후 특정위치의 값을 answer
3. Arrays.sort 배열정리 사용
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = {};
answer = new int [commands.length];
for (int i =0; i < commands.length ; i++){
int start = commands[i][0];
int end = commands[i][1];
int point = commands[i][2];
int length = end-start +1;
int [] arr = new int[length];
start -=1;
for( int j =0 ; j <length ; j++){
arr[j] = array[start++];
System.out.println(arr[j] + " " + array[j]);
}
Arrays.sort(arr);
answer[i] = arr[point-1];
}
return answer;
}
}
다른사람의 코드
copyoRange 를 통해 for문을 안돌리고 단축 심플하게 가능
int[] temp = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]);
반응형
'IT > 알고리즘_JAVA' 카테고리의 다른 글
[프로그래머스] 소수찾기 (2) | 2022.03.23 |
---|---|
[프로그래머스] 가장큰수 (0) | 2020.06.01 |
[프로그래머스] 탑 (0) | 2020.05.31 |
[프로그래머스] 완주하지 못한 선수 (0) | 2020.05.27 |
[코딜리티]FrogRiverOne (0) | 2020.05.11 |
Comments