Tree BFS
LC #637Easy
Average of Levels in Binary Tree
Tree BFS
AmazonGoogleProblem
Return the average value of nodes on each level of a binary tree.
treebfs
Constraints
- ›1 ≤ n ≤ 10⁴
- ›-2³¹ ≤ Node.val ≤ 2³¹ − 1
Example
Input
root = [3, 9, 20, 15, 7]Output
[3.0, 14.5, 11.0]Why
L0 avg: 3/1=3, L1 avg: (9+20)/2=14.5, L2 avg: (15+7)/2=11