-
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
프로그래머스 K번째수 문제입니다.
#include <string> #include <vector> #include <algorithm> using namespace std; vector<int> solution(vector<int> array, vector<vector<int>> commands) { vector<int> answer; for(auto iter : commands){ int start = iter[0]; int end = iter[1]; int idx = iter[2]; vector<int> temp; for(int i=start-1;i<end;i++){ temp.push_back(array[i]); } sort(temp.begin(),temp.end()); answer.push_back(temp[idx-1]); } return answer; }
아이디어
sort를 이용한 직관적 풀이
'알고리즘 > 프로그래머스' 카테고리의 다른 글
Programers H-Index (0) 2022.03.12 Programers 가장 큰 수 (0) 2022.03.12 Programers 전화번호 목록 (0) 2022.03.12 Programers 완주하지 못한 선수 (0) 2022.03.12 2022 카카오 블라인드 코딩테스트 6번 (0) 2022.02.05 댓글