Search⌘ K
AI Features

Solution: Univalued Binary Tree

Understand how to verify if a binary tree is uni-valued by applying depth-first search. This lesson teaches the recursive technique to compare parent and child node values, enabling you to determine tree uniformity with an optimal time and space complexity.

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