문제접근![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
범위만큼 tmp에 입력
•
tmp 정렬
•
answer 벡터에 tmp의 원하는 인덱스 값 삽입
놓쳤던 부분![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
코드![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
4040 KB
0.01 ms
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
vector<int> tmp;
for (int i = 0; i < commands.size(); i++)
{
for (int j = commands[i][0] - 1; j < commands[i][1]; j++)
{
tmp.push_back(array[j]);
}
sort(tmp.begin(), tmp.end());
answer.push_back(tmp[commands[i][2] - 1]);
tmp.clear();
}
return answer;
}
C++
복사