250. Count Univalue Subtrees
Description
Given the root
of a binary tree, return the number of uni-value subtrees.
A uni-value subtree means all nodes of the subtree have the same value.
Example 1:
![](https://assets.leetcode.com/uploads/2020/08/21/unival_e1.jpg)
1 | Input: root = [5,1,5,5,5,null,5] |
Example 2:
1 | Input: root = [] |
Example 3:
1 | Input: root = [5,5,5,5,5,null,5] |
Constraints:
- The number of the node in the tree will be in the range
[0, 1000]
. -1000 <= Node.val <= 1000
Hints/Notes
- N/A
Solution
Language: C++
1 | /** |