1003.cpp (451B)
1 class Solution { 2 public: 3 bool isValid(const string &s) const { 4 static char st[20001]; 5 int n = 0; 6 for (const char c : s) { 7 if (c != 'c') 8 st[n++] = c; 9 else { 10 if (n < 2) return false; 11 if (st[n - 1] != 'b') return false; 12 if (st[n - 2] != 'a') return false; 13 n -= 2; 14 } 15 } 16 return n == 0; 17 } 18 };