第41天。 今天的题目是Validate Stack Sequences: 简单题,直接模拟就好了: 1bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {2 stack<int> st;3 int i = 0;4 for(auto &t: popped) {5 if (!st.empty() && st.top() == t) {6 st.pop();7 } else {8 while(i < pushed.size() && pushed[i] != t) {9 st.push(pushed[i]);10 i++;11 }12 if (pushed.size() == i) return false;13 i++;14 }15 }2 collapsed lines16 return true;17}