https://leetcode.com/problems/validate-binary-search-tree


Runtime: 172 ms, faster than 12.94% of Go online submissions for Validate Binary Search Tree.
Memory Usage: 11 MB, less than 5.74% of Go online submissions for Validate Binary Search Tree.


```go
//type TreeNode struct {
//	Val   int
//	Left  *TreeNode
//	Right *TreeNode
//}

func get_all_values_of_a_subtree(node *TreeNode) []int {
	l := make([]int, 0)
	if node != nil {
		l = append(l, node.Val)
		if node.Left != nil {
			l = append(l, node.Left.Val)
		}
		if node.Right != nil {
			l = append(l, node.Right.Val)
		}
		l = append(l, get_all_values_of_a_subtree(node.Left)...)
		l = append(l, get_all_values_of_a_subtree(node.Right)...)
		return l
	}
	return l
}

func get_max_of_a_list(list []int) int {
	max_value := list[0]
	for _, value := range list[1:] {
		if value > max_value {
			max_value = value
		}
	}
	return max_value
}

func get_min_of_a_list(list []int) int {
	mix_value := list[0]
	for _, value := range list[1:] {
		if value < mix_value {
			mix_value = value
		}
	}
	return mix_value
}

func travel(node *TreeNode) bool {
	if node != nil {
		left_list := get_all_values_of_a_subtree(node.Left)
		right_list := get_all_values_of_a_subtree(node.Right)

		if len(left_list) > 0 {
			if get_max_of_a_list(left_list) < node.Val {
				// normal
			} else {
				return true
			}
		}

		if len(right_list) > 0 {
			if get_min_of_a_list(right_list) > node.Val {
				// normal
			} else {
				return true
			}
		}

		return travel(node.Left) || travel(node.Right)
	}

	return false
}

func isValidBST(root *TreeNode) bool {
	//7:04
	return !travel(root)
	//7:14
}
```