luoheng
10/6/2019 - 10:22 AM

searchBST

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