DAYS
HOUR
MINS
SEC
Error
Given a binary tree, count the number of Single Valued Subtrees. A Single Valued Subtree is one in which all the nodes have same value.
Example 1
Input :
5
/ \
1 5
/ \ \
5 5 5
Output : 4
Explanation :
There are 4 subtrees with single values.
Example 2:
Input:
5
/ \
4 5
/ \ \
4 4 5
Output: 5
Explanation:
There are five subtrees with single values.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes