题目:
题解:
class Solution:
def isValidSerialization(self, preorder: str) -> bool:
pre = 1
for i in preorder.split(','):
if i.isdigit():
if pre == 0:
return False
pre += 1
else:
if pre == 0:
return False
pre -= 1
return pre == 0