프로그래머스 - K번째수

well-life-gm·2021년 11월 15일
0

프로그래머스

목록 보기
54/125

프로그래머스 - K번째수

1점짜리 문제이다.

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

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    
    for(int i=0;i<commands.size();i++) {
        int start = commands[i][0];
        int end = commands[i][1];
        int idx = commands[i][2];
        vector<int> tmp(array.begin() + start - 1, array.begin() + end);
        sort(tmp.begin(), tmp.end());
        answer.push_back(tmp[idx - 1]);
    }
    
    return answer;
}
profile
내가 보려고 만든 블로그

0개의 댓글