mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 17:44:10 +08:00
add: leetcode 0700 solution
This commit is contained in:
@ -0,0 +1,20 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user