946. Validate Stack Sequences验证栈序列

网址:https://leetcode.com/problems/validate-stack-sequences/

参考:https://leetcode.com/problems/validate-stack-sequences/discuss/197667/Java-straight-forward-stack-solution.

模拟过程

class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped)
{
stack<int> temp;
int i = ;
for(int num : pushed)
{
temp.push(num);
while(!temp.empty() && temp.top() == popped[i])
{
temp.pop();
i++;
}
}
return temp.empty();
}
};

946. Validate Stack Sequences验证栈序列

上一篇:oracle数据库实例,数据库的理解


下一篇:android手机抓wireshark包的步骤-tcpdump(需root权限)