Given the root of a binary tree, return the average value of the nodes on each level, as an array ordered from the top level down. Answers within 10^-5 of the actual value are accepted.
Given the root of a binary tree, return the average value of the nodes on each level, as an array ordered from the top level down. Answers within 10^-5 of the actual value are accepted.
Example 1:
Input: {"root":[3,9,20,null,null,15,7]}
Output: [3,14.5,11]
Constraints:
The number of nodes in the tree is in the range [1,104].
−231≤Node.val≤231−1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[3,9,20,null,null,15,7]}
Put the root 3 in the queue. The queue will always hold exactly one level when a pass begins.