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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems