250. Count Univalue Subtrees

Problem

Count the number of uni-value subtrees (all nodes have the same value) in a binary tree.

Given the root of a binary tree, count the number of subtrees where all nodes have the same value. A subtree is defined as any node and all its descendants.

Examples
Input: [5,1,5,5,5,null,5]
Output: 4
Hints
Related Problems

250. Count Univalue Subtrees

Count the number of uni-value subtrees (all nodes have the same value) in a binary tree.