본문 바로가기

Algorithm/Programmers

[정렬] K번째 수

728x90

 

 

#include <string>
#include <vector>
#include <algorithm>


using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    vector<int> temp;

    int length = commands.size();

    for(int i=0; i<length; i++){
        
        //command에 들어온 수만큼 반복
        for(int j=commands[i][0]; j<=commands[i][1]; j++){
            //printf("%d\n",j);
            temp.push_back(array[j-1]);  
        }
        //printf("???\n");
        sort(temp.begin(), temp.end());
        answer.push_back(temp[commands[i][2]-1]);
        temp.clear();
        
    }
    
    return answer;
}
728x90