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