124 Binary Tree Maximum Path Sum
题目: 124 Binary Tree Maximum Path Sum
这道题就是分别算出左子树和右子树的可能最大和,然后对Path的值进行更新即可
class Solution:def __init__(self):self.ans = -100000def maxPathSum(self, root):self.getSum(root)return self.ansdef getSum(self, root):if not root:return 0left = max(0, self.getSum(root.left))right = max(0, self.getSum(root.right))self.ans = max(self.ans, left + root.val + right)return root.val + max(left,right)
转载于:https://www.cnblogs.com/dapanshe/p/4648001.html
124 Binary Tree Maximum Path Sum相关推荐
- 【重点】LeetCode 124. Binary Tree Maximum Path Sum
LeetCode 124. Binary Tree Maximum Path Sum 参考链接:http://zxi.mytechroad.com/blog/tree/leetcode-124-bin ...
- 【LeetCode】124. Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...
- 124. Binary Tree Maximum Path Sum
题目: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any seque ...
- leetcode @python 124. Binary Tree Maximum Path Sum
题目链接 https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题目原文 Given a binary tree, find the ...
- LeetCode 124. Binary Tree Maximum Path Sum
原题 求二叉树的最大路径和 Given a binary tree, find the maximum path sum. For this problem, a path is defined as ...
- 124. Binary Tree Maximum Path Sum 二叉树中的最大路径和
Title 给定一个非空二叉树,返回其最大路径和. 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列.该路径至少包含一个节点,且不一定经过根节点. 示例 1: 输入: [1,2,3] 1 ...
- Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum 题目链接:https://leetcode.com/problems... dfs对每个node,查一下包含这个node的最大路径值. /** ...
- Leetcode | Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- Leetcode: Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.Fo ...
最新文章
- Replica Sets+Sharding方案之真枪实弹篇
- 什么是用户与计算机硬件之间的桥梁,计算机应用基础简答题(附答案)
- VS 2005 文本编码小技巧
- java day25【Junit单元测试 、反射 、 注解】
- 黄聪:PHP 防护XSS,SQL,代码执行,文件包含等多种高危漏洞
- 无线WIFI上网监控串联部署方案
- 读书笔记 - 《疯狂的站长》
- 突破灰色按钮原理讲解
- 蓝桥杯省赛训练营——日期的计算
- IEEE邮件爆出:禁止华为员工审稿,惨遭网友吐槽!
- 【计算机网络】网线规格的鉴别与接线方法
- 边缘检测(opencv_python下)
- 如何成功实施结对编程
- 推理规则/经典规则(排中律/反证法双重否定消除)
- Linux操作系统的需要安装和使用
- ZSTD 解压缩前端处理方案
- 关于VS/VC工程编译不过去这件事
- 自定义chrome浏览器导航条样式
- 知识图谱 | (3) 知识图谱技术综述(下)
- 每月交通费6000多!张家口女子去北京上班,每天通勤5小时坚持3年