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.

Examples

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

All nodes have value 1.

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

Node with value 5 differs from the rest (all 2s), so the tree is not uni-valued.

Input:root = [7]
Output:true
Explanation:

A single node tree is always univalued since there's only one value to check.

Constraints

  • 1 ≤ nodes ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!