当前位置:网站首页>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 <= 107rootis a binary search tree.1 <= val <= 107class 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)
边栏推荐
- 如何開發引入小程序插件
- Sparse array [matrix]
- ESP32 hosted
- K210 learning notes (IV) k210 runs multiple models at the same time
- Analyse des risques liés aux liaisons de microservices
- Pinctrl subsystem and GPIO subsystem
- Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
- Oracle hint understanding
- Matlab draws a cute fat doll
- Poj3414 extensive search
猜你喜欢

Depth first DFS and breadth first BFS -- traversing adjacency tables

实战:fabric 用户证书吊销操作流程

Performance monitoring of database tuning solutions

Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space

Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture

Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~

How can Bluetooth in notebook computer be used to connect headphones

Huawei cloud modelarts text classification - takeout comments

Win11运行cmd提示“请求的操作需要提升”的解决方法

Stored procedures and stored functions
随机推荐
How to develop and introduce applet plug-ins
Dbeaver executes multiple insert into error processing at the same time
The statistics of leetcode simple question is the public string that has appeared once
Oracle advanced query
等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
The real situation of programmers
Stored procedures and stored functions
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
Meituan dynamic thread pool practice ideas, open source
Sentinel production environment practice (I)
Sparse array [matrix]
AD637使用筆記
了解 Android Kotlin 中 DataStore 的基本概念以及为什么应该停止在 Android 中使用 SharedPreferences
Oracle is sorted by creation time. If the creation time is empty, the record is placed last
Implementation technology of recovery
Codeforces 12D ball tree array simulation 3 sorting elements
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
Basic grammar of interview (Part 1)
What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method
Reptile practice