K번째수
https://programmers.co.kr/learn/courses/30/lessons/42748
코딩테스트 연습 - K번째수
[1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3]
programmers.co.kr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
vector<int> solution(vector<int> array, vector<vector<int>> commands) { | |
vector<int> answer; | |
for (const auto& cmd : commands) | |
{ | |
int start = cmd[0] - 1; | |
int end = cmd[1]; | |
int target= cmd[2] - 1; | |
vector<int> temp; | |
for(int i = start; i < end; ++i) | |
{ | |
temp.push_back(array[i]); | |
} | |
sort(temp.begin(), temp.end()); | |
answer.push_back(temp[target]); | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
음양 더하기 (0) | 2022.05.08 |
---|---|
내적 (0) | 2022.05.08 |
두 개 뽑아서 더하기 (0) | 2022.05.08 |
이상한 문자 만들기 (0) | 2022.05.08 |
자릿수 더하기 (0) | 2022.05.08 |