less than 1 minute read

Given a binary tree root, return the sum of all values in the tree.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root

https://binarysearch.com/problems/Tree-Sum

Examples

Example 1

Input

  • root =

Output

  • answer = 11

Explanation

11 = 1 + 2 + 3 + 5

Example 2

Input

  • root =

Output

  • answer = 6

Explanation

6 = 1 + 2 + 3

Solution

Leave a comment