nikunjsoni

946

Mar 23rd, 2021
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
  4.         int i, j;
  5.         i=j=0;
  6.         for(int x: pushed){
  7.             pushed[i++] = x;
  8.             while(i>0 && pushed[i-1] == popped[j])
  9.                 i--, j++;
  10.         }
  11.         return i == 0;
  12.     }
  13. };
RAW Paste Data