#965

Univalued Binary Tree

newbie · 250 · lc easy +18 · verified · 72.9% accepted · 1,978 likes · top 83%

Description

A binary tree is univalued if every node carries the same value. Given the root of a binary tree, return true if the tree is univalued and 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

Code

1
2
3
4
5
6
7
8
9