当前位置:网站首页>Lc236. nearest common ancestor of binary tree
Lc236. nearest common ancestor of binary tree
2022-06-29 09:39:00 【996 chongchongchong】

def lowestCommonAncestor(self, root, p, q):
""" :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode """
def recur(root,p,q):
if not root:
return
if root.val == p.val or root.val == q.val: # Put it here , After finding a subtree with this node as the root node, there is no need to access it . because :
return root # situation 1 : The other value is on the subtree of the currently found node , The current node is the answer
left = recur(root.left,p,q) # situation 2 : Another value is not on the subtree of the current node , Then the subtree of the current node can be found elsewhere without access
right = recur(root.right,p,q)
if left and right: # Put it in the following position , The result information can be passed forward through the return value
return root
return left if left else right
return recur(root,p,q)
边栏推荐
- Ue4 installe le plug - in datasmith dans la version 4.20-23
- LSM6DSL之SPI驱动
- The difference between cokkie and session
- 转载 :判断对象是否具有属性的5种方法
- Wechat applet determines the file format of URL
- Mac mysql数据库基本操作
- The former security director of Uber faced fraud allegations and had concealed data leakage incidents
- MH/T 6040航空材料烟密度试验
- Wechat applet custom multi selector
- Pytorch Summary - sensor on GPU
猜你喜欢

SSD Improvement cfenet

你知道BFD是什么吗?一文详解BFD协议原理及使用场景

Data visualization: the four quadrants of data visualization teach you to correctly apply icons

UE4 蓝图修改Array 中Get a copy 为 reference

Pytorch Summary - Automatic gradient

Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation

ThinkPHP 6 uses mongodb

五心公益红红娘团队

Ue4 installe le plug - in datasmith dans la version 4.20-23

Wechat applet custom multi selector
随机推荐
长安链GO语言智能合约环境搭建及使用
The former security director of Uber faced fraud allegations and had concealed data leakage incidents
Understanding of singleton mode
c语言printf大家族系列
Redo after JS rotation view (longer full version, can be run)
五心公益红红娘团队
数据仓库:金融/银行业的分层架构篇
Reading notes on how to connect the network - Web server request and response (IV)
Fabrication d'une calculatrice d'addition simple basée sur pyqt5 et Qt Designer
1.4 机器学习方法之回归问题
Official STM32 chip package download address stm32f10x stm32f40x Download
【技术开发】酒精测试仪解决方案开发设计
Remember to customize the top navigation bar of wechat applet
UE4 插件报错 Cannot open include file: ‘ModuleManager.h‘解决
Highlight in the middle of the navigation bar at the bottom of wechat applet
Factory mode
Mongodb persistence
Recursive RBAC menu level display infinite classification
Yotact real-time instance segmentation
你必须知道的23个最有用的Elasticseaerch检索技巧