LeetCode 1120. Maximum Average Subtree

打印 上一主题 下一主题

主题 1743|帖子 1743|积分 5229

原题链接在这里:https://leetcode.com/problems/maximum-average-subtree/
题目:
Given the root of a binary tree, return the maximum average value of a subtree of that tree. Answers within 10-5 of the actual answer will be accepted.
A subtree of a tree is any node of that tree plus all its descendants.
The average value of a tree is the sum of its values, divided by the number of nodes.
Example 1:
  1. Input: root = [5,6,1]
  2. Output: 6.00000
  3. Explanation:
  4. For the node with value = 5 we have an average of (5 + 6 + 1) / 3 = 4.
  5. For the node with value = 6 we have an average of 6 / 1 = 6.
  6. For the node with value = 1 we have an average of 1 / 1 = 1.
  7. So the answer is 6 which is the maximum.
复制代码
Example 2:
  1. Input: root = [0,null,1]
  2. Output: 1.00000
复制代码
Constraints:
<ul ><li >The number of nodes in the tree is in the range [1, 104].<li >0

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

天津储鑫盛钢材现货供应商

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表