链接: link

class MinStack {
public:
MinStack() {
}
void push(int val) {
st1.push(val);
if (st2.size())
{
if (st2.top() >= val)
{
st2.push(val);
}
}
else
st2.push(val);
}
void pop() {
int a=st1.top();
st1.pop();
if (a == st2.top())
{
st2.pop();
}
}
int top() {
return st1.top();
}
int getMin() {
return st2.top();
}
private:
stack<int> st1;
stack<int> st2;
};
链接: [link]
(https://www.youkuaiyun.com/https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=13&&tqId=11174&rp=1&ru=/activity/oj&qru=/ta/coding-interviews/question-ranking)

class Solution {
public:
bool IsPopOrder(vector<int>& pushV, vector<int>& popV) {
stack<int> st1;
int pushi = 0, popi = 0;
while (pushi<pushV.size())
{
st1.push(pushV[pushi++]);
while(!st1.empty()&&st1.top() == popV[popi])
{
st1.pop();
popi++;
}
}
return st1.empty();
}
};
577

被折叠的 条评论
为什么被折叠?



