プログラマc++k番号
K番目の数
結果
問題を解く
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> res;
for(int i=0;i<commands.size();i++)
{
vector<int> answer;
for(int j=commands[i][0];j<=commands[i][1];j++)
answer.push_back(array[j-1]);
sort(answer.begin(),answer.end());
res.push_back(answer[commands[i][2]-1]);
}
return res;
}
iからjに切り、答えを入れて並べ替え、k個の数をresに入れて返す.Reference
この問題について(プログラマc++k番号), 我々は、より多くの情報をここで見つけました https://velog.io/@jaranda/프로그래머스-c-k번째수テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol