Python | Leetcode Python题解之第331题验证二叉树的前序序列化
题目:
题解:
class Solution:def isValidSerialization(self, preorder: str) -> bool:pre = 1for i in preorder.split(','):if i.isdigit():if pre == 0:return Falsepre += 1else:if pre == 0:return Falsepre -= 1return pre == 0