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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


 

- Java

import java.util.*;
class Solution {
    public int[] solution(int[] array, int[][] commands) {
        int[] answer = new int[commands.length];
        for(int i=0;i<answer.length;i++){
            ArrayList<Integer> aa = new ArrayList<>();
            for (int j=commands[i][0]-1;j<commands[i][1];j++)
                aa.add(array[j]);
            Collections.sort(aa);
            answer[i]=aa.get(commands[i][2]-1);
        }
        return answer;
    }
}

 

- Ruby

넣고 빼기 딱 좋은 루비

def solution(array, commands)
    answer = []
    commands.each{|a|
        b=[]
        for i in a[0]-1..a[1]-1
            b.append(array[i])
        end
        
        b.sort!
        answer.append(b[a[2]-1])
        
    }
    return answer
end

+ Recent posts