题目:
题解:
func isValidSerialization(preorder string) bool {n := len(preorder)slots := 1for i := 0; i < n; {if slots == 0 {return false}if preorder[i] == ',' {i++} else if preorder[i] == '#' {slots--i++} else {// 读一个数字for i < n && preorder[i] != ',' {i++}slots++ // slots = slots - 1 + 2}}return slots == 0
}