Notice
Recent Posts
Recent Comments
Today
Total
01-11 08:45
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์ •๋ ฌ] k๋ฒˆ์งธ์ˆ˜ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์ •๋ ฌ] k๋ฒˆ์งธ์ˆ˜

WonderJay 2022. 7. 1. 23:54
728x90
๋ฐ˜์‘ํ˜•
SMALL

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

vector ์˜ assign ์„ ์ด์šฉํ•˜์—ฌ temp vector ์— slice ํ•œ ๋‹ค์Œ sorting ํ•˜์—ฌ ์š”๊ตฌํ•˜๋Š” ์œ„์น˜์˜ ๊ฐ’์„ answer ๋ฐฐ์—ด์— insert ํ•œ๋‹ค.

 

 

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

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;

    int n = commands.size();


    for (int i = 0; i < n; i++)
    {
        vector<int> temp;
        temp.assign(array.begin() + commands[i][0] - 1, array.begin() + commands[i][1]);

        sort(temp.begin(), temp.end());

        answer.insert(answer.begin() + i, temp[commands[i][2] - 1]);
    }

    return answer;
}

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments