[프로그래머스] K번째수
정렬 - K번째수
- 문제 링크 : K번째수
사용 언어 : Python3
사기적인 Python의 텍스트 슬라이싱..
def solution(array, commands):
answer = []
for i, j, k in commands :
temp = sorted(array[i-1:j])
answer.append(temp[k-1])
return answer
원치 않게 c++과 병행하고 있는데 파이썬과 너무 차이난다..
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
vector<int> temp;
for(int i=0; i<commands.size(); i++){
for(int j=commands[i][0]-1; j<commands[i][1]; j++){
temp.push_back(array[j]);
}
sort(temp.begin(), temp.end());
answer.push_back(temp[commands[i][2]-1]);
temp.clear();
}
return answer;
}
