mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
18 lines
268 B
Go
18 lines
268 B
Go
package leetcode
|
|
|
|
import "strings"
|
|
|
|
func isValidSerialization(preorder string) bool {
|
|
nodes, diff := strings.Split(preorder, ","), 1
|
|
for _, node := range nodes {
|
|
diff--
|
|
if diff < 0 {
|
|
return false
|
|
}
|
|
if node != "#" {
|
|
diff += 2
|
|
}
|
|
}
|
|
return diff == 0
|
|
}
|