当前位置:网站首页>76. nearest common ancestor of binary tree
76. nearest common ancestor of binary tree
2022-06-29 18:57:00 【It's Joe Joe】
subject

Ideas

Code
class Solution:
def lowestCommonAncestor(self, root: TreeNode, p: TreeNode, q: TreeNode) -> TreeNode:
if not root or root == p or root == q:
return root
left = self.lowestCommonAncestor(root.left, p, q)
right = self.lowestCommonAncestor(root.right, p, q)
if not left and not right:
return # 1.
if not left:
return right # 3.
if not right:
return left # 4.
return root # 2. if left and right:
边栏推荐
- Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
- MySQL Enterprise Development Specification
- 压测并发数的确定
- Fastdfs
- 《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
- Svg circle drawing path animation
- C Primer Plus 第12章_存储类别、链接和内存管理_代码和练习题
- js文本粒子动态背景
- 【网络是怎么连接的】第三章 探索集线器,交换机和路由器
- What is a multi paradigm programming language and what does "multi paradigm" mean?
猜你喜欢

1. use stm32cubemx to establish stm32g030c8t6 project

Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology

Apache InLong百万亿级数据流处理

The strategy of convertible bonds -- - (cake sharing, premium, forced redemption, downward revision, double low)

Up to 81.98%! Announcement of undergraduate study rate of more than 100 "double first-class" Universities
![报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket

Adobe Premiere foundation - opacity (mixed mode) (XII)

Error building sqlsession problem

2. 银河麒麟离线模式下如何安装MySQL数据库

75.二叉搜索树额最近公共祖先
随机推荐
优雅书写Controller(参数验证+统一异常处理)
curl下载示例
Redis bloom filter and cuckoo filter
svg画圆路径动画
Hello, do you have any official website samples for MySQL CDC, PostgreSQL CDC? Give me a link to learn
sql server备份以及还原的命令操作
Interview question 10.10 Rank of digital stream
Stepping on the pit: json Parse and json stringify
How to use the oak camera on raspberry pie?
JS text particle dynamic background
How to use the low code platform of the Internet of things for service management?
isalpha()方法介绍
centos 7.5安装mysql 8.0.27----yum
Cannot retrieve repository metadata 处理记录
山东大学项目实训(七)添加导航栏选择城市
6.29 simulation summary
《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
移动端测试
PHP实现二维数组按指定的键名排序的方法
Chapter 02_ MySQL data directory