|
@@ -0,0 +1,18 @@
|
|
|
+/**
|
|
|
+ * 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)
|
|
|
+ }
|
|
|
+}
|