leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0331.cpp (500B)


0 class Solution { 1 public: 2 bool isValidSerialization(const string &preorder) const { 3 const int n = size(preorder); 4 int size = 1; 5 6 for (int i = 0; i < n; i++) { 7 if (preorder[i] == ',') continue; 8 size--; 9 if (size < 0) return false; 10 if (preorder[i] != '#') { 11 while (i < n && preorder[i + 1] != ',') 12 i++; 13 size += 2; 14 } 15 } 16 17 return size == 0; 18 } 19 };