题目:
题解:
class Solution:
def isValidSerialization(self, preorder: str) -> bool:
p = preorder.split(",")
n = len(p)
cn = c3 = 0
for i, x in enumerate(p):
if x == "#": c3 += 1
else: cn += 1
if c3 > cn:
return i+1 == n #if end is true
return False