프로그래머스 k번째수

조항주·2022년 4월 18일
0

algorithm

목록 보기
16/50
post-thumbnail

문제

https://programmers.co.kr/learn/courses/30/lessons/42748

코드

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    for(auto i:commands){
        vector<int> temp;
        for(int j=i[0]-1;j<=i[1]-1;j++)
            temp.push_back(array[j]);
        
        sort(temp.begin(),temp.end());
        answer.push_back(temp[i[2]-1]);
    }
    
    return answer;
}

풀이

큰 어려움 없이 문제에서 하라는대로 하면됩니다. 코드 보시면 temp에다가 문제에서 주는 범위만큼 array값을 입력하고 sort를 사용해서 정렬했습니다

0개의 댓글