题解 | #最大体重的牛#
最大体重的牛
https://www.nowcoder.com/practice/0333d46aec0b4711baebfeb4725cb4de
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param op string字符串vector * @param vals int整型vector<vector<>> * @return int整型vector */ vector<int> max_weight_cow(vector<string>& op, vector<vector<int> >& vals) { // write code here int len = op.size(); vector<int> t; vector<int> ans; for(int i=0; i<len; ++i) { if(op[i]=="MaxCowStack") { ans.emplace_back(-1); } else if(op[i]=="push") { ans.emplace_back(-1); t.emplace_back(vals[i][1]); } else if(op[i]=="getMax") { int max_num=0; for(int j=0; j<t.size(); ++j) max_num = max(max_num, t[j]); ans.emplace_back(max_num); } else if(op[i]=="pop") { ans.emplace_back(-1); t.pop_back(); } else if(op[i]=="top") { ans.emplace_back(t.back()); } } return ans; } };
虚数五行区解题中心 文章被收录于专栏
非淡泊无以明志,非宁静无以致远