当前位置:网站首页>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)
边栏推荐
- Talking about MySQL index
- Summary of El and JSTL precautions
- Evolution of large website architecture and knowledge system
- The real situation of programmers
- Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
- Server optimization of performance tuning methodology
- DataGrid directly edits and saves "design defects"
- The difference between MVVM and MVC
- Solutions for unexplained downtime of MySQL services
- boundary IoU 的计算方式
猜你喜欢
Shell script, awk uses if, for process control
Livelocks and deadlocks of concurrency control
科技云报道:算力网络,还需跨越几道坎?
Matlab draws a cute fat doll
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
EBS Oracle 11g cloning steps (single node)
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method
Reptile practice
随机推荐
Database recovery strategy
Blocking protocol for concurrency control
Pl/sql basic case
Hysbz 2243 staining (tree chain splitting)
MySQL actual combat 45 lecture learning (I)
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
MySQL服务莫名宕机的解决方案
Practice: fabric user certificate revocation operation process
阿龙的感悟
Server optimization of performance tuning methodology
Depth first DFS and breadth first BFS -- traversing adjacency tables
Recovery technology with checkpoints
Microservice link risk analysis
Nacos 的安装与服务的注册
"Chris Richardson microservices series" uses API gateway to build microservices
Evolution of large website architecture and knowledge system
The real situation of programmers
如何开发引入小程序插件
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
如何快速体验OneOS