题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
class Solution {
public:
bool IsPopOrder(vector<int> pushV,vector<int> popV) {
int size = pushV.size();
stack<int> stk;
int j = 0;
for(int i = 0; i < size; ++i){
while(j < size && (stk.empty() || stk.top() != popV[i])){
stk.push(pushV[j]);
++j;
}
if(stk.top() == popV[i]){
stk.pop();
} else {
return false;
}
}
return true;
}
};
