[Programmers] K 번째 수

Time Lapse :NONE

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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>forCalcCopy;

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

}

return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/KthNum/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.