๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
vector<int> solution(vector<string> operations) {
vector<int>answer;
multiset<int>set;
for(int i=0; i<operations.size(); i++){
string operation = operations[i].substr(0,1);
int num = stoi(operations[i].substr(2));
if(operation=="I") set.insert(num);
else if(operation=="D"){
if(set.empty()) continue;
if(num==1) set.erase(--set.end());
if(num==-1) set.erase(set.begin());
}
}
if(!set.empty()){
answer.push_back(*(--set.end()));
answer.push_back(*(set.begin()));
}
else{
answer.push_back(0);
answer.push_back(0);
}
return answer;
}
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ( Level 2) (0) | 2021.10.22 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ ํ๋ฒํธ ๋ชฉ๋ก( Level 2) (0) | 2021.10.22 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ฐ์ ๋ค์ง์ด ๋ฐฐ์ด๋ก ๋ง๋ค๊ธฐ( Level 1) (0) | 2021.10.22 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ด์ํ ๋ฌธ์ ๋ง๋ค๊ธฐ( Level 1) (0) | 2021.10.22 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ ๋ํ๊ธฐ( Level 1) (0) | 2021.10.22 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ฃผํ์ง ๋ชปํ ์ ์( Level 1) (0) | 2021.10.22 |
๋๊ธ