首页 > 其他 > 详细

剑指 Offer 31. 栈的压入、弹出序列

时间:2020-10-28 19:55:37      阅读:45      评论:0      收藏:0      [点我收藏+]

技术分享图片

思路

思路来源:https://leetcode-cn.com/problems/validate-stack-sequences/

 技术分享图片

 

 技术分享图片

 1 class Solution {
 2 public:
 3     bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
 4         stack<int> s;
 5         int i = 0;
 6         for(int e: pushed) {
 7             s.push(e);
 8             while(!s.empty() && s.top() == popped[i]) {
 9                 s.pop();
10                 i++;
11             }
12         }
13 
14         return s.empty();
15     }
16 
17 };

 

剑指 Offer 31. 栈的压入、弹出序列

原文:https://www.cnblogs.com/FengZeng666/p/13891630.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!