package
0.0.0-20241125063422-a7e1e0bf04b0
Repository: https://github.com/blueblue0102/leetcode-go.git
Documentation: pkg.go.dev

# README

98. Validate Binary Search Tree

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

驗證所給定的樹是否為 BST
並不能只是單純的檢查 root.Val > root.Left.Valroot.Val < root.Right.Val
然後檢查 root.Leftroot.Right 是否也符合這個特性

graph TB
    A((5))-->B((4))
    A-->C((6))
    C-->D((3))
    C-->E((7))

觀察其中節點 6 雖然符合 BST
root53 不應該被放在 5 的右側

Takeaway

  • Tree Traversal
  • Binary Search Tree