알고리즘 연습/프로그래머스
[level 1] k 번째 수 , 2차 풀이
_h.j
2020. 7. 11. 00:59
728x90
https://programmers.co.kr/learn/courses/30/lessons/42748
첫 번째 풀이
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
vector<int> temp;
for(int t = 0;t< commands.size() ;t++){
int i=commands[t][0]-1,j= commands[t][1]-1,k=commands[t][2]-1;
for(int z = i ; z <= j ; z++)
temp.push_back(array[z]);
//정렬
for(int x = 1 ; x < j - i + 1 ;x++){
int key = temp[x];
int y = x-1;
while(y>-1 && temp[y]>key){
temp[y+1]=temp[y];
y--;
}
temp[y+1]= key;
}
answer.push_back(temp[k]);
temp.clear();
}
return answer;
}
두 번째 풀이
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
for(auto elem : commands){
vector <int>
}
return answer;
}
728x90