728x90
https://school.programmers.co.kr/learn/courses/30/lessons/42748
(1) C++
#include <string>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
for(int i = 0; i<commands.size(); i++){
vector<int> array2;
for(int j = commands[i][0] - 1; j < commands[i][1]; j++){
array2.push_back(array[j]);
}
sort(array2.begin(), array2.end());
answer.push_back(array2[commands[i][2] - 1]);
}
return answer;
}
(2) Python
def solution(array, commands):
answer = []
for i in commands:
split_array = array[i[0] - 1 : i[1]]
split_array.sort()
answer.append(split_array[i[2] - 1])
return answer
728x90
'Study > Coding Test' 카테고리의 다른 글
[프로그래머스] 베스트앨범 Python, C++ (0) | 2023.08.01 |
---|---|
[프로그래머스] 의상 Python, C++ (0) | 2023.08.01 |
[프로그래머스] 게임 맵 최단거리 Python, C++ (0) | 2023.07.31 |
[프로그래머스] 네트워크 Python, C++ (0) | 2023.07.31 |
[백준] 15486 - 퇴사 2 Python (0) | 2023.07.07 |