devLupin / algorithm

PS
1 stars 0 forks source link

프로그래머스-Lv1 K번째수 #4

Open devLupin opened 1 year ago

devLupin commented 1 year ago

문제 출처

내 코드

[간결한 코드]

#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;

    for(int i = 0; i < commands.size(); i++) {
        temp = array;
        sort(temp.begin() + commands[i][0] - 1, temp.begin() + commands[i][1]);
        answer.push_back(temp[commands[i][0] + commands[i][2]-2]);
    }

    return answer;
}