Easy · Trees

Sum of nodes

Given the root of a binary tree, return the sum of all its node values, or 0 if the tree is empty.

Examples

Example 1

[1,2,3,4,5,6,7]

Output: sum = 28

Example 2

[5,3,8,null,4,null,10]

Output: sum = 30

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems