๐Ÿ“ฆ jtr109 / go-playground

๐Ÿ“„ lib.go ยท 21 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21// https://leetcode.com/problems/search-in-a-binary-search-tree/

package searchinabinarysearchtree

import "github.com/jtr109/lcutils/treenode"

type TreeNode = treenode.TreeNode

func searchBST(root *TreeNode, val int) *TreeNode {
	if root == nil {
		return nil
	}
	if val == root.Val {
		return root
	} else if val > root.Val {
		return searchBST(root.Right, val)
	} else {
		return searchBST(root.Left, val)
	}
}