We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
vector<int>getMax(vector<string>const&_operations){usingnamespacestd;autocommand=0;autostck=stack<int>();autoresult=vector<int>();for(autoop:_operations){command=op[0];switch(command){case'1':{stck.emplace(max(stck.empty()?0:stck.top(),stoi(op.substr(2))));break;}case'2':{stck.pop();break;}case'3':{result.emplace_back(stck.top());break;}default:{assert(false&&"not known command");}}}returnresult;}
Cookie support is required to access HackerRank
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++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )