当前位置:网站首页>【二叉树-困难】124. 二叉树中的最大路径和
【二叉树-困难】124. 二叉树中的最大路径和
2022-08-10 01:52:00 【菜菜2022】
【题目】
【代码】
# 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 visit(self,root):
if not root:
return 0
l=max(self.visit(root.left),0)
r=max(self.visit(root.right),0)
self.cnt=max(self.cnt,l+r+root.val)
# print(root.val," l:",l," r:",r)
return root.val+max(l,r)
def maxPathSum(self, root: Optional[TreeNode]) -> int:
self.cnt=-30000000
self.visit(root)
return self.cnt
边栏推荐
- Teach you how to write performance test cases
- 51单片机驱动HMI串口屏,串口屏的下载方式
- 首次在我们的centos上安装MySQL
- Summary of Web Performance Testing Models
- 墨西哥大众VW Mexico常见的几种label
- 已备案域名用国外服务器会不会掉备案?
- Not, even the volume of the king to write code in the company are copying and pasting it reasonable?
- 夏克-哈特曼波前传感器
- 不是吧,连公司里的卷王写代码都复制粘贴,这合理?
- QT中,QTableWidget 使用示例详细说明
猜你喜欢
随机推荐
OpenCV图像处理学习四,像素的读写操作和图像反差函数操作
Shader Graph learns various special effects cases
OpenCV图像处理学习二,图像掩膜处理
Chip Information|Semiconductor revenue growth expected to slow to 7%, Bluetooth chip demand still growing steadily
Open3D 网格均匀采样
如何让数据库中的数据同步
《GB39732-2020》PDF download
Janus实际生产案例
[QNX Hypervisor 2.2用户手册]10.14 smmu
阿里云OSS文件上传
【web渗透】SSRF漏洞超详细讲解
用于X射线光学器件的哈特曼波前传感器
Unity碰撞和触发
高压之下,必有懦夫
浏览器中location详解
Premint工具,作为普通人我们需要了解哪些内容?
Unity editor extension interface uses List
[语法糖] 关于类别字符串到类别数字id的映射
通关剑指 Offer——剑指 Offer II 012. 左右两边子数组的和相等
Under pressure, there must be cowards









