leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1003.cpp (451B)
0 class Solution {
1 public:
2 bool isValid(const string &s) const {
3 static char st[20001];
4 int n = 0;
5 for (const char c : s) {
6 if (c != 'c')
7 st[n++] = c;
8 else {
9 if (n < 2) return false;
10 if (st[n - 1] != 'b') return false;
11 if (st[n - 2] != 'a') return false;
12 n -= 2;
13 }
14 }
15 return n == 0;
16 }
17 };