MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / isValidBST

Function isValidBST

validate_binary_search_tree_98/solution.go:5–18  ·  view source on GitHub ↗
(root *TreeNode)

Source from the content-addressed store, hash-verified

3import . "github.com/austingebauer/go-leetcode/structures"
4
5func isValidBST(root *TreeNode) bool {
6 if root == nil || (root.Left == nil && root.Right == nil) {
7 return true
8 }
9
10 in := inorderTraversal(root)
11 for i := 1; i < len(in); i++ {
12 if in[i-1] >= in[i] {
13 return false
14 }
15 }
16
17 return true
18}
19
20func inorderTraversal(root *TreeNode) []int {
21 if root == nil {

Callers 1

Test_isValidBSTFunction · 0.85

Calls 1

inorderTraversalFunction · 0.85

Tested by 1

Test_isValidBSTFunction · 0.68