[Programmers] 이중 우선순위 큐

Time Lapse :20min 24sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <stdlib.h>
#include <cstring>
using namespace std;
//20:24
vector<int> solution(vector<string> operations) {
vector<int> prefix;
for(int i=0;i<operations.size();i++){
if(operations[i][0]=='I'){
string s = operations[i].substr(2,operations[i].length()-2);
prefix.push_back(atoi(s.c_str()));
}
else{
if(prefix.size()==0)
continue;
if(operations[i].length()==3){
prefix.erase(prefix.begin()+prefix.size()-1);
}
else
prefix.erase(prefix.begin());
}
sort(prefix.begin(),prefix.end());
}
vector<int> answer;
if(prefix.size()!=0){
answer.push_back(prefix[prefix.size()-1]);
answer.push_back(prefix[0]);}
else{
answer.push_back(0); answer.push_back(0);
}
return answer;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/doublePQ/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.