123456789101112131415161718 |
- /**
- * Definition for a binary tree node.
- * type TreeNode struct {
- * Val int
- * Left *TreeNode
- * Right *TreeNode
- * }
- */
- func searchBST(root *TreeNode, val int) *TreeNode {
- if root == nil || root.Val == val {
- return root
- }
- if val < root.Val {
- return searchBST(root.Left, val)
- } else {
- return searchBST(root.Right, val)
- }
- }
|