当前位置:网站首页>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)
边栏推荐
- Oracle views the data size of a table
- EBS Oracle 11g cloning steps (single node)
- 元宇宙中的三大“派系”
- What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
- A long's perception
- A trip to Suzhou during the Dragon Boat Festival holiday
- Pl/sql basic case
- Leetcode simple question check whether all characters appear the same number of times
- Codeforces 12D ball tree array simulation 3 sorting elements
- 科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
猜你喜欢
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
Meituan dynamic thread pool practice ideas, open source
Sparse array [matrix]
MySQL服务莫名宕机的解决方案
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Web3为互联网带来了哪些改变?
Technology cloud report: how many hurdles does the computing power network need to cross?
Bitbucket installation configuration
database mirroring
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
随机推荐
Daily question brushing record (XIV)
ESP32 hosted
Solutions for unexplained downtime of MySQL services
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Business learning of mall commodity module
How can Bluetooth in notebook computer be used to connect headphones
Overview of concurrency control
HDU 4391 paint the wall segment tree (water
Common interview questions of JVM manufacturers
Comment développer un plug - in d'applet
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"
实战:fabric 用户证书吊销操作流程
Evolution of large website architecture and knowledge system
AD637使用筆記
Pl/sql basic syntax
Search: Future Vision (moving sword)
1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
Leetcode simple question: check whether each row and column contain all integers
MySQL服务莫名宕机的解决方案