Search⌘ K
AI Features

Solution: Univalued Binary Tree

Explore how to verify if a binary tree is uni-valued by using depth-first search to compare each parent node's value with its children. Understand the solution's logic, recursive approach, and analyze its time and space complexities.

Statement

A binary tree is considered uni-valued if every node in the tree contains the same value.

Given the root of a binary tree, return true if the tree is uni-valued, or false otherwise.

Constraints:

  • The number of nodes in the tree is in the range [1,100][1, 100].

  • 00 \leq ...