2265. Count Nodes Equal to Average of Subtree ⭐
Medium
Given the root
of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree.
Note:
The average of
n
elements is the sum of then
elements divided byn
and rounded down to the nearest integer.A subtree of
root
is a tree consisting ofroot
and all of its descendants.
Example 1:
Example 2:
Constraints:
The number of nodes in the tree is in the range
[1, 1000]
.0 <= Node.val <= 1000
解題
原本的程式碼又醜又笨,討論區這個解答我最喜歡:
Runtime: 0 ms, faster than 100.00%
Memory Usage: 4.3 MB, less than 92.31%
Last updated