700. Search in a Binary Search Tree(BST)
程序员文章站
2022-06-08 09:24:10
...
链接:https://leetcode.com/problems/search-in-a-binary-search-tree/
题目:BST的查找,直接查找即可。
class Solution {
public:
TreeNode* searchBST(TreeNode* root, int val) {
if(!root)
return NULL;
else if(root->val == val)
return root;
else if(root->val > val )
return searchBST(root->left,val);
else
return searchBST(root->right,val);
}
};
推荐阅读
-
Convert Sorted Array to Binary Search Tree
-
二分查找(binary search)java实现及时间复杂度
-
【leetcode】-700. Search in a Binary Search Tree 查找二叉搜索树
-
LeetCode C++ 454. 4Sum II【Hash Table/Sort/Two Pointers/Binary Search】
-
Leetcode——108. Convert Sorted Array to Binary Search Tree
-
Leetcode 108. Convert Sorted Array to Binary Search Tree
-
96. Unique Binary Search Trees
-
POJ 1757 Binary Search G++
-
Binary Search:349. Intersection of Two Arrays
-
LeetCode 235--二叉搜索树的最近公共祖先 ( Lowest Common Ancestor of a Binary Search Tree ) ( C语言版 )