标签:end false pre pop seq test 验证 || 序列
1 class Solution 2 { 3 public: 4 bool validateStackSequences(vector<int>& pushed, vector<int>& popped) 5 { 6 stack<int> s; 7 int pushedEnd = -1; 8 for(int i = 0;i < popped.size();i ++) 9 { 10 if(s.empty()||s.top()!=popped[i]) 11 { 12 pushedEnd ++; 13 for(;pushedEnd < pushed.size() 14 && pushed[pushedEnd]!=popped[i];pushedEnd ++) 15 { 16 s.push(pushed[pushedEnd]); 17 } 18 if(pushedEnd==pushed.size()) 19 return false; 20 } 21 else if(s.top()==popped[i]) 22 s.pop(); 23 } 24 return true; 25 } 26 };
Leetcode-946 验证栈序列(Validate Stack Sequences)
标签:end false pre pop seq test 验证 || 序列
原文地址:https://www.cnblogs.com/Asurudo/p/10016518.html