https://programmers.co.kr/learn/courses/30/lessons/42748
Level1 문제이길래 간단할 줄 알았는데 생각보다 귀찮았던 문제였습니다.
제 풀이가 조금 복잡한건지 포스팅 후에는 다른 사람 풀이를 한번 참고해보도록 해야겠습니다.
이 문제에서는 디버깅이 중요하다고 느꼈고 실제로 차근차근히 풀면 금방 해결할 수 있었던 문제였던 것 같아요.4
알고리즘 문제 풀이를 꾸준히 하려고 노력 중이지만 여러 여건상 쉽지가 않네요 아쉽습니다 ㅎㅎ
정답 코드
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
int cnt;
for(int i=0; i<commands.length; i++){
int[] temp = new int[commands[i][1]-commands[i][0]+1];
cnt = 0;
for(int j=commands[i][0]-1; j<=commands[i][1]-1; j++){
temp[cnt] = array[j];
cnt++;
}
Arrays.sort(temp);
answer[i] = temp[commands[i][2]-1];
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 - 조이스틱(오답) (0) | 2020.04.12 |
---|---|
프로그래머스 - H - index (0) | 2020.04.12 |
프로그래머스 - 위장 (1) | 2020.04.10 |
프로그래머스 - 완주하지 못한 선수 (0) | 2020.04.10 |
프로그래머스 - 쇠막대기 (2) | 2020.04.06 |