프로그래머스 K번째 수

A Code AM·2020년 3월 24일
0

Algorithm

목록 보기
2/9
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    vector<int> tmp;
    
    //commands의 사이즈 만큼 돌리자(배열 주어졌다고 3으로 돌리면 테스트때 망한다..)
    for(int i = 0; i < commands.size(); i++)
    {
    //tmp에 [i][0] -1 만큼 > 문제는 순서를 index로 주지 않았다는걸 명심하자 
        tmp.assign(array.begin() + commands[i][0] - 1, array.begin() + commands[i][1]);
        sort(tmp.begin(), tmp.end());
        answer.push_back(tmp[commands[i][2]-1]);
    }
    
    return answer;
}

어렵지 않지만 우선 vector를 다를 줄은 알아야 한다

profile
배움기록

0개의 댓글