当前位置:网站首页>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:
边栏推荐
- 山东大学项目实训(七)添加导航栏选择城市
- 熊猫跑酷js小游戏代码
- RocketMQ的tag过滤和sql过滤
- Page Object与数据驱动测试
- The table ‘table_ Name 'is full exception troubleshooting and solution
- Apache Doris basic usage summary
- 什么是多范式编程语言,其中的“多范式”是什么意思?
- js将秒转换成“2h30min50s”的格式
- [tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
- Redis (I) -- getting started with redis (2) -- redis data type
猜你喜欢

Anaconda安装并配置jupyter notebook远程

JDBC knowledge

Travel card "star picking" hot search first! Stimulate the search volume of tourism products to rise

Cannot retrieve repository metadata 处理记录

The table ‘table_ Name 'is full exception troubleshooting and solution

How to use the low code platform of the Internet of things for service management?

【网络是怎么连接的】第三章 探索集线器,交换机和路由器

元素等待机制

深度学习---三好学生各成绩所占权重问题(2)

JWT login authentication
随机推荐
Hello, do you have any official website samples for MySQL CDC, PostgreSQL CDC? Give me a link to learn
PHP 输出两个指定日期之间的所有日期
Adobe Premiere foundation - opacity (matte) (11)
Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
Shell basic syntax -- process control
JS converts seconds to "2h30min50s" format
Data analysis time series prediction
数据仓库模型分层ODS、DWD、DWM实战
These advantages of the Institute are really fragrant! The landing rate is still very high!
PHP实现二维数组按指定的键名排序的方法
程序员值得收藏的几款代码截图美化工具播
SD6.24集训总结
2022.6.29-----leetcode. five hundred and thirty-five
面试题 10.10. 数字流的秩
什么是多范式编程语言,其中的“多范式”是什么意思?
金鱼哥RHCA回忆录:DO447构建高级作业工作流--创建工作流作业模板并启动工作流作业
JWT login authentication
MySQL 企业级开发规范
JS-判断数组键名是否存在
第八届“互联网+”大赛 | 云原生赛道邀你来挑战