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:
trueExplanation:
All nodes have value 1.
Input:
root = [2,2,2,5,2]Output:
falseExplanation:
Node with value 5 differs from the rest (all 2s), so the tree is not uni-valued.
Input:
root = [7]Output:
trueExplanation:
A single node tree is always univalued since there's only one value to check.
Constraints
- •
1 ≤ nodes ≤ 100