less than 1 minute read

Given a binary tree root, return whether all values in the tree are the same.

Constraints

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

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

Examples

Example 1

Input

  • root =

Output

  • answer = False

Explanation

There is a node with a value 9 while others are 2

Example 2

Input

  • root =

Output

  • answer = True

Explanation

Every node has the value 2

Solution

Leave a comment