코딩테스트/프로그래머스 - LV 1
[프로그래머스] k번째수
웅드
2024. 2. 13. 22:17
- 풀이
#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++){
vector<int> v;
for(int j=commands[i][0]-1; j < commands[i][1]; j++ ){
v.push_back(array[j]);
}
sort(v.begin(), v.end());
answer.push_back(v[commands[i][2]-1]);
}
return answer;
}
반응형