题目来源:
https://leetcode-cn.com/problems/search-in-a-binary-search-tree/
题目描述:
代码如下:
class Solution {
public TreeNode searchBST(TreeNode root, int val) {
if (root == null) {
return null;
}
if (root.val == val) {
return root;
}
if (root.val > val && root.left != null) {
return searchBST(root.left, val);
} else if (root.val < val && root.right != null) {
return searchBST(root.right, val);
}
return null;
}
}