• Home
  • About
    • Jiwon Jeong photo

      Jiwon Jeong

      끊임없이 배우며 성장하는 엔지니어

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
    • All Categories
  • Projects

[프로그래머스] - K번째 수

17 May 2021

Reading time ~1 minute

풀이 (성공)

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

using namespace std;

bool compare(int a, int b){
    if(a<b){
        return true;
    }else{
        return false;
    }
}

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


PS Share Tweet +1