Below question content has been taken from :
crazycoderzz.wordpress.com/count-the-number-of-unival-subtrees-in-a-binary-tree/
Though below question is tagged as Easy one, but it is not that easy also.
It can be easy for Googlers, but not for me.
crazycoderzz.wordpress.com/count-the-number-of-unival-subtrees-in-a-binary-tree/
Though below question is tagged as Easy one, but it is not that easy also.
It can be easy for Googlers, but not for me.
Below I have used bottom-up approach, even the same is also suggested on above website.
Below I am giving Java code as per my current understanding, & below code may be wrong
as I tested it for above given examples only.
It will really helpful if one can provide the correct code, in case of any concern, so that others
can also learn. The problem asked around this concept on LeetCode, I can say easy & you can see its solution here, 965. Univalued Binary Tree
On above website C++ code is given which one can refer.
Below I am giving Java code as per my current understanding, & below code may be wrong
as I tested it for above given examples only.
It will really helpful if one can provide the correct code, in case of any concern, so that others
can also learn. The problem asked around this concept on LeetCode, I can say easy & you can see its solution here, 965. Univalued Binary Tree
On above website C++ code is given which one can refer.