mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-23 09:51:45 +08:00
21 lines
325 B
Go
21 lines
325 B
Go
package leetcode
|
|
|
|
type TreeNode struct {
|
|
Val int
|
|
Left *TreeNode
|
|
Right *TreeNode
|
|
}
|
|
|
|
func searchBST(root *TreeNode, val int) *TreeNode {
|
|
if root == nil {
|
|
return nil
|
|
}
|
|
if root.Val == val {
|
|
return root
|
|
} else if root.Val < val {
|
|
return searchBST(root.Right, val)
|
|
} else {
|
|
return searchBST(root.Left, val)
|
|
}
|
|
}
|