lc-go/solutions/7/q700/solution.go
2026-01-09 18:00:28 +09:00

24 lines
346 B
Go

package q700
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func searchBST(root *TreeNode, val int) *TreeNode {
if root == nil {
return nil
}
switch {
case val == root.Val:
return root
case val > root.Val:
return searchBST(root.Right, val)
default:
return searchBST(root.Left, val)
}
}
var _ = searchBST