You are viewing a single comment's thread. Return to all comments →
C++ O(1)
vector<int> getMax(vector<string> operations) { stack<int> s; vector<int> v; for (auto &ops : operations) { switch (ops[0]) { case '1':{ int x = stoi(ops.substr(1)); if (s.size() && s.top() > x) s.push(s.top()); else s.push(x); break; } case '2':{ s.pop(); break; } case '3':{ v.push_back(s.top()); break; } } } return v; }
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++ O(1)