#965

Univalued Binary Tree

easy · verified · 72.9% accepted · 1,978 likes · top 83%

tree · depth-first search · breadth-first search · binary tree

⊣ practice⊣ open on leetcode ↗

Description

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

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

Example 1:

Input: root = [1,1,1,1,1,null,1]
Output: true

Example 2:

Input: root = [2,2,2,5,2]
Output: false

Solution