ㅁㄴㅇㄹ
K번쨰 수 (Level 1) 본문
별 어려울것 없는 구현 문제였다. vector의 정렬은 algorithm 라이브러리의 sort함수를 사용해 해결하였다.
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> ans;
for (int i = 0; i < commands.size(); i++) {
vector<int> cmd = commands[i];
int start = cmd[0]; int end = cmd[1]; int idx = cmd[2];
vector<int> temp;
for (int j = start; j <= end; j++) {
temp.push_back(array[j-1]);
}
sort(temp.begin(), temp.end());
ans.push_back(temp[idx - 1]);
}
return ans;
}
'코딩테스트 연습 > 프로그래머스' 카테고리의 다른 글
[2021 카카오 채용연계형 인턴십] 숫자 문자열과 영단어 (Level 1) (0) | 2021.08.03 |
---|---|
[2019 카카오 개발자 겨울 인턴십] 크레인 인형뽑기 게임 (Level 1) (0) | 2021.07.23 |
[카카오 인턴] 키패드 누르기(Level 1) (0) | 2021.07.22 |