Binary Tree Sum - aloalgo

Binary Tree Sum

Easy

You are given the root of a binary tree.

Your task is to calculate the sum of all node values in the tree.

Return the total sum of all node values.

Example 1

Input
1243
Output
10
Explanation:

The sum of all node values (1 + 2 + 3 + 4) is 10.

Example 2

Input
None
Output
0
Explanation:

An empty tree has a sum of 0.

Example 3

Input
1
Output
1
Explanation:

A single node tree has a sum equal to its value.

Loading...
Input
1243
Output
10

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!