Given a binary tree, count the number of uni-value subtrees.
A Uni-value subtree means all nodes of the subtree have the same value.
Example
No.1
Input: root = {5,1,5,5,5,#,5}
Output: 4
Explanation:
1 | 5 |
No.2
Input: root = {1,3,2,4,5,#,6}
Output: 3
Explanation:
1 | 1 |
Code
1 | public class TreeNode { |
1 | private int count = 0; |