Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10^-5 of the actual answer will be accepted.
Each node has a val (integer value), a left child, and a right child. Children may be null.
The tree is given as a level-order array where null represents a missing node. For example, [3,9,20,null,null,15,7] represents:
3
/ \
9 20
/ \
15 7
The averages for this tree are:
root = [3, 9, 20, null, null, 15, 7][3, 14.5, 11]root = [3, 9, 20, 15, 7][3, 14.5, 11]root = [1][1]The number of nodes in the tree is in the range [1, 10^4]-2^31 <= Node.val <= 2^31 - 1Expected time complexity: O(n)Run your code to see results
Use Cmd+Enter to run