Search⌘ K
AI Features

Solution: Univalued Binary Tree

Explore how to identify a uni-valued binary tree by applying a depth-first search strategy. This lesson guides you through checking each node's value compared to its children, and shows how to efficiently return true or false based on this property. Gain insight into the recursive solution, time complexity, and space complexity considerations for balanced and skewed trees.

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 ...