go 代码
func verifySequenceOfBST(sequence []int) bool{
if len(sequence) <= 2 {
return true
}
rootValue := sequence[len(sequence)-1]
i := 0
for i < len(sequence)-1 && sequence[i] < rootValue {
i++
}
j := i
for j < len(sequence)-1 {
if sequence[j] < rootValue {
return false
}
j++
}
return verifySequenceOfBST(sequence[0:i]) && verifySequenceOfBST(sequence[i:len(sequence)-1])
}