programming language/Algorithm
[프로그래머스 Level1] K번째 수
jellylucy
2021. 7. 23. 13:52
문제
입출력
문제풀이
간단하게 풀었다.
answer 최종값을 만들때 따로 빼서 만들다가 한번에 넣어서 만들었다.
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
for(int j = 0;j<commands.size();j++){
vector<int> arr;
for(int i = commands[j][0]-1;i<commands[j][1];i++){
arr.push_back(array[i]);
}
sort(arr.begin(), arr.end());
answer.push_back(arr[commands[j][2]-1]);
}
// for(int k =0;k<sizeof(arr[0])/sizeof(int);k++){
// answer.push_back(arr[k][commands[k][2]]);
// }
return answer;
}