700. Search in a Binary Search Tree
问题
You are given the root of a binary search tree (BST) and an integer val.Find the node in the BST that the node’s value equals val and return the subtree rooted with that node. If such a node does not exist, return null.
搜索二叉树。
递归,如果现有根节点为空则返回空。
如果根节点的值大于搜索值则搜索其左子节点。
如果根节点的值小于搜索值则搜索其左右节点。
1 | /** |
700. Search in a Binary Search Tree
https://xuanhe95.github.io/2022/04/14/700-Search-in-a-Binary-Search-Tree/