As per some website-
I can think of below solution & one can see the sample to print data of each level in the tree. And printing the tree data can further have vaious flavors.
InvertBinaryTree
Nitin Agrawal |
|
As per some website- I can think of below solution & one can see the sample to print data of each level in the tree. And printing the tree data can further have vaious flavors. InvertBinaryTree
0 Comments
As per one website this question from LeetCode problem#85 is asked in Google & it is tagged as 'Medium', though it is 'Hard' on LeetCode.
Again, if you get the approach, then it can be medium, else it is damn difficult. 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. 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. |