当前位置:网站首页>leetcode:814. Binary tree pruning [DFS]
leetcode:814. Binary tree pruning [DFS]
2022-07-22 04:51:00 【White speed Dragon King's review】
analysis
Find the whole subtree 0 Of kill fall
ac code
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def pruneTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
# check Is it all 0
def check(node):
if not node:
return True
if node.left is None and node.right is None and node.val == 0:
return True
if node.left is None and node.right is None and node.val == 1:
return False
return node.val == 0 and check(node.left) and check(node.right)
def change(node):
if check(node):
return None
if node.left: node.left = change(node.left)
if node.right: node.right = change(node.right)
return node
return change(root)
summary
Simple check + change
边栏推荐
- Understand the volatile implementation of JVM from the bottom, CPU cache, cache consistency MESI, store bufferi, nvalidate queue and other knowledge
- ORM学员管理系统
- Verification of implicit conversion rules for different types of arithmetic operations in C language
- [fuzzy neural network] design of fuzzy neural network controller based on Simulink
- Anfulai embedded weekly report no. 274: 2022.07.11--2022.07.17
- (resolved) for camerads, HR = m_ pGraph-> Connect(m_pCameraOutput, m_pGrabberInput); Solutions to implementation failures
- flink操作hudi数据表
- Nacos相关概念小总结
- 《ASP.NET Core 6框架揭秘》实例演示[04]:自定义依赖注入框架
- 流(stream),文件(File),IO
猜你喜欢
【低代码】1387- 试着换个角度理解低代码平台设计的本质
window10系统常用操作
Deeply understand the timeout setting of istio traffic management
Cesium加载3D Tiles数据
Mapstruct code generator realizes object transformation
Mozilla基金会发布2022 Internet Health报告:2030年AI将为全球经济贡献15.7万亿,美去年AI投资是中国的近三倍
年中盘点 | 2022年,PaaS 再升级
go-系统监控
ICML2022最佳论文奖:从数百万个预测结构中学习蛋白质逆折叠
Hcip notes sorting 2022/7/15
随机推荐
SDL2 简明教程(二):创建一个空的窗口
软考 系统架构设计师 简明教程 | 软件开发模型
[low code] 1387 try to understand the essence of low code platform design from another angle
There are always errors in installing plug-ins in NPM
巴比特 | 元宇宙每日必读:要求高级政府官员披露其在NFT上的所有投资?美国政府道德办公室发布的这份法律咨询还说了什么?...
Step by step introduction to the development framework based on sqlsugar (12) -- split the content of the page module into components to realize the division and rule processing
《ASP.NET Core 6框架揭秘》实例演示[04]:自定义依赖注入框架
Techempower web框架性能测试第21轮结果发布--asp.net core继续前进
打假AI无主灯,欧瑞博、艾拉物联、绿米Aqara谁是玩真的?
steam API
Mozilla基金会发布2022 Internet Health报告:2030年AI将为全球经济贡献15.7万亿,美去年AI投资是中国的近三倍
Anfulai embedded weekly report no. 274: 2022.07.11--2022.07.17
HCIP笔记整理 2022/7/14
中间件
(resolved) for camerads, HR = m_ pGraph-> Connect(m_pCameraOutput, m_pGrabberInput); Solutions to implementation failures
cookie和session「建议收藏」
有点酷,使用 .NET MAUI 探索太空
IO多路复用
JS array method
SDL2 简明教程(一):使用 Cmake 和 Conan 构建 SDL2 编程环境