티스토리 뷰

  • 코드구현
      class Solution {
        public int[] solution(int[] array, int[][] commands) {
    
          // answer의 길이는 commands의 길이와 동일
          int[] answer = new int[commands.length];
    
          // commands 길이만큼 돌면서
          for (int i = 0; i < commands.length; i++) {
    
            // i는 a, j는 b, k는 c로 할당
            int a, b, c;
            a = commands[i][0];
            b = commands[i][1];
            c = commands[i][2];
    
            // copyOfRange(arr, from, to): array 배열의 a-1 인덱스부터 시작, b까지 배열 복사
            int[] temp = Arrays.copyOfRange(array, a - 1, b);
    
            // 정렬
            Arrays.sort(temp);
    
            // c번째 원소==c-1 를 answer배열에 담음
            answer[i] = temp[c - 1];
    
          } // for
    
          return answer;
        }
      }​
  • 실행결과
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
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
글 보관함