그럴듯한 개발 블로그
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/42748?language=cpp 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    
    // commands [startidx + 1, endidx + 1, targetidx + 1]
    for (int i = 0; i < commands.size(); i++)
    {
        int start_idx = commands[i][0] - 1, end_idx = commands[i][1] - 1, target_idx = commands[i][2] - 1;
        vector<int> v(end_idx - start_idx + 1);
        for (int j = 0; j <= end_idx - start_idx; j++)
            v[j] = array[j + start_idx];
        sort(v.begin(), v.end());
        answer.push_back(v[target_idx]);
    }
    return answer;
}

easy

반응형
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!