顺时针打印矩阵
二维数组的花式遍历技巧 :: labuladong的算法小抄
提交一直有问题,等有时间搞一下数组遍历的专题
2.栈的压入、弹出序列
利用辅助栈
![](https://img-blog.csdnimg.cn/img_convert/f000404f4aaaa17746d3a4f13cc256bb.png)
![](https://img-blog.csdnimg.cn/img_convert/5faa63cf4ad1228b7fe4dc04679f7034.png)
class Solution {
public:
bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
if(pushed.size()!=popped.size()) return false;
stack<int> st;
int i=0;
for(int num : pushed){
st.push(num);
while(!st.empty()&&popped[i]==st.top()){
st.pop();
i++;
}
}
return st.empty();
}
};