摘要: 深度优先搜索 class Solution { /** * 因为和有可能为负数,因此初始值取无穷小 */ int max = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { maxSum(root); return max; } / 阅读全文
posted @ 2021-12-29 20:05 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int maxLength = 0; public int longestUnivaluePath(TreeNode root) { depth(root); return maxLength; } /** * 在《104. 二叉树的最大深度》的基础上 阅读全文
posted @ 2021-12-29 10:23 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)