当前位置:网站首页>700. Search in a Binary Search Tree. Sol
700. Search in a Binary Search Tree. Sol
2022-07-05 22:16:00 【isee_ nh】
It's the same Easy subject , But it's not easy to write succinctly
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
.
Example 1:
Input: root = [4,2,7,1,3], val = 2 Output: [2,1,3]
Example 2:
Input: root = [4,2,7,1,3], val = 5 Output: []
Constraints:
- The number of nodes in the tree is in the range
[1, 5000]
. 1 <= Node.val <= 107
root
is a binary search tree.1 <= val <= 107
class Solution: def searchBST(self, root, val): if not root or root.val == val: return root else: if root.val <= val: return self.searchBST(root.right,val) else: return self.searchBST(root.left,val)
边栏推荐
- Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"
- Serializability of concurrent scheduling
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- [Yugong series] go teaching course in July 2022 004 go code Notes
- Blocking of concurrency control
- Some tutorials install the database on ubantu so as not to occupy computer memory?
- Cross end solutions to improve development efficiency
- Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
- Installation of VMware Workstation
- Hcip day 16
猜你喜欢
Reptile practice
每日刷题记录 (十四)
Promql demo service
2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
Nacos 的安装与服务的注册
Oracle advanced query
Damn, window in ie open()
Alternating merging strings of leetcode simple questions
Sentinel production environment practice (I)
Technology cloud report: how many hurdles does the computing power network need to cross?
随机推荐
HDU 4391 paint the wall segment tree (water
Database tuning solution
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
如何向mongoDB中添加新的字段附代码(全)
Oracle triggers
Promql demo service
Calculation method of boundary IOU
Shell script, awk condition judgment and logic comparison &||
C language knowledge points link
Decorator learning 01
K210学习笔记(四) K210同时运行多个模型
如何开发引入小程序插件
装饰器学习01
Cross end solutions to improve development efficiency
AD637使用笔记
Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
The difference between MVVM and MVC
Form artifact
AD637使用筆記
PyGame practical project: write Snake games with 300 lines of code