题目: 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相关推荐

  1. 【重点】LeetCode 124. Binary Tree Maximum Path Sum

    LeetCode 124. Binary Tree Maximum Path Sum 参考链接:http://zxi.mytechroad.com/blog/tree/leetcode-124-bin ...

  2. 【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 ...

  3. 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 ...

  4. leetcode @python 124. Binary Tree Maximum Path Sum

    题目链接 https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题目原文 Given a binary tree, find the ...

  5. LeetCode 124. Binary Tree Maximum Path Sum

    原题 求二叉树的最大路径和 Given a binary tree, find the maximum path sum. For this problem, a path is defined as ...

  6. 124. Binary Tree Maximum Path Sum 二叉树中的最大路径和

    Title 给定一个非空二叉树,返回其最大路径和. 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列.该路径至少包含一个节点,且不一定经过根节点. 示例 1: 输入: [1,2,3] 1 ...

  7. Binary Tree Maximum Path Sum

    Binary Tree Maximum Path Sum 题目链接:https://leetcode.com/problems... dfs对每个node,查一下包含这个node的最大路径值. /** ...

  8. 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. ...

  9. 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 ...

最新文章

  1. Replica Sets+Sharding方案之真枪实弹篇
  2. 什么是用户与计算机硬件之间的桥梁,计算机应用基础简答题(附答案)
  3. VS 2005 文本编码小技巧
  4. java day25【Junit单元测试 、反射 、 注解】
  5. 黄聪:PHP 防护XSS,SQL,代码执行,文件包含等多种高危漏洞
  6. 无线WIFI上网监控串联部署方案
  7. 读书笔记 - 《疯狂的站长》
  8. 突破灰色按钮原理讲解
  9. 蓝桥杯省赛训练营——日期的计算
  10. IEEE邮件爆出:禁止华为员工审稿,惨遭网友吐槽!
  11. 【计算机网络】网线规格的鉴别与接线方法
  12. 边缘检测(opencv_python下)
  13. 如何成功实施结对编程
  14. 推理规则/经典规则(排中律/反证法双重否定消除)
  15. Linux操作系统的需要安装和使用
  16. ZSTD 解压缩前端处理方案
  17. 关于VS/VC工程编译不过去这件事
  18. 自定义chrome浏览器导航条样式
  19. 知识图谱 | (3) 知识图谱技术综述(下)
  20. 每月交通费6000多!张家口女子去北京上班,每天通勤5小时坚持3年

热门文章

  1. Power of Cryptography
  2. ubuntu rar文件乱码
  3. 【算法python实现】 -- 岛屿的个数
  4. Elasticsearch中如何进行排序(中文+父子文档+嵌套文档)
  5. 【NOIP2016】蚯蚓 --队列模拟
  6. 数学(莫比乌斯反演):HAOI 2011 问题B
  7. my wordpress
  8. vs2010 将.mc编译为.rc文件
  9. SQL Server中的重要观点
  10. php 织梦wap源码,织梦手机静态页生成插件 DEDE WAP静态化 手机端生成静态