```
class Solution(object):
def isValidSerialization(self, preorder):
s = preorder.split(',');
i = len(s) - 1;
while i >= 0:
if s[i] != '#':
if not s or s.pop() != '#':
return(False);
if not s or s.pop() != '#':
return(False);
s[i] = '#';
i -= 1;
return(len(s) == 1 and s[0] == '#');
```