알고리즘/문제풀이

[정렬] K번째 수

lipnus 2018. 9. 19. 01:16
반응형
[프로그래머스] K번째수 

https://programmers.co.kr/learn/courses/30/lessons/42748


import java.util.*;

class Solution {
public int[] solution(int[] array, int[][] commands) {

List<Integer> answerList = new ArrayList<>();

for(int[] command : commands){
List<Integer> list = new ArrayList<>();
for(int i=command[0]; i<=command[1]; i++){
list.add( array[i-1] );
}
Collections.sort(list);
answerList.add( list.get(command[2]-1) );
}//for(command)


int[] answerArr = new int[answerList.size()];
for(int i=0; i<answerList.size(); i++){
answerArr[i] = answerList.get(i);
}

return answerArr;
}
}



반응형

'알고리즘 > 문제풀이' 카테고리의 다른 글

[구현] 줄기세포배양  (0) 2018.09.24
[정렬] H-index  (0) 2018.09.23
[Hash] 베스트앨범  (0) 2018.09.18
[Hash] 완주하지 못한 선수  (0) 2018.09.17
의석이의 우뚝 선 산  (0) 2018.09.14