BRANCH SUMS


     Write a function that takes root of binary tree as a input and returns sum of its nodes depths.

Approach -  Create a variable depth_sum and depth, depth will store current depth of binary tree and d_sum will store the total sum of depths.


 O(n) time, O(h) space[h is the height of binary tree]

node depths solution


 Please leave comment for any suggestions or topic you would like to read.


 

Comments