Skip to content

Commit 140a912

Browse files
committed
700. 二叉搜索树中的搜索
1 parent 0fe8df0 commit 140a912

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.gatsby;
2+
3+
/**
4+
* @ClassName: _700SearchInBinarySearchTree
5+
* @Description: leetcode 700 二叉搜索树中的搜索
6+
* @author: Gatsby
7+
* @date: 2022/5/17 14:13
8+
*/
9+
10+
public class _700SearchInBinarySearchTree {
11+
public TreeNode searchBST(TreeNode root, int val) {
12+
if (root == null) return null;
13+
if (root.val == val) return root;
14+
else if (val < root.val) return searchBST(root.left, val);
15+
else return searchBST(root.right, val);
16+
}
17+
}
18+
19+

0 commit comments

Comments
 (0)