Skip to main content
LeetCode 965, Easy. Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

A binary tree is <strong>uni-valued</strong> if every node in the tree has the same value. Given the <code>root</code> of a binary tree, return <code>true</code> if the given tree is <strong>uni-valued</strong>, or <code>false</code> otherwise.

Examples

Example 1
Example 2

Constraints

  • The number of nodes in the tree is in the range [1, 100]
  • 0 <= Node.val < 100

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026