You are viewing a single comment's thread. Return to all comments →
C++ solution
vector<int> getMax(vector<string> operations) { int a = 0; stack<int> mem; stack<int> max; vector<int> res; for(auto i : operations){ if(i.size() > 1){ a = stoi(i.substr(2)); mem.push(a); if(max.empty() || max.top() <= a){ max.push(a); } } else{ if(i == "2"){ if(mem.top() == max.top()) max.pop(); mem.pop(); } if(i == "3"){ res.push_back(max.top()); } } } return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
C++ solution