s*******r 发帖数: 9 | 1 250 Count Univalue Subtrees
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.
For example:
Given binary tree,
5
/ \
1 5
/ \ \
5 5 5
return 4.
195 / 197 test cases passed.
有一个case通不过
Input:
[5,5,5,5,5,null,5]
Output:
4
Expected:
6
实在没看出来有6个,是我题目理解不对? | l*****a 发帖数: 14598 | 2 for the three 5 in the right,
all 3 5 is one
top 2 5 is one
bottom 2 5 is one
the bottom 5 is one
【在 s*******r 的大作中提到】 : 250 Count Univalue Subtrees : 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. : For example: : Given binary tree, : 5 : / \ : 1 5 : / \ \ : 5 5 5
| s*******r 发帖数: 9 | 3 for this case [5,5,5,5,5,null,5] the tree should be like
5
/
5 5
/
5 5 5
Sorry I still not get your answer.
My understanding is
the bottom three nodes contributes 3
the second left node subtree contribute 1
so the total is 4?
【在 l*****a 的大作中提到】 : for the three 5 in the right, : all 3 5 is one : top 2 5 is one : bottom 2 5 is one : the bottom 5 is one
| l******s 发帖数: 3045 | 4 root and root.right are another 2.
【在 s*******r 的大作中提到】 : for this case [5,5,5,5,5,null,5] the tree should be like : 5 : / : 5 5 : / : 5 5 5 : Sorry I still not get your answer. : My understanding is : the bottom three nodes contributes 3 : the second left node subtree contribute 1
| j**********3 发帖数: 3211 | | l******s 发帖数: 3045 | 6 顺便问一下lz付费后看到的公司面试的那些信息质量如何?比glassdoor 和
geeksforgeeks上列出来的那些怎样? | n*******s 发帖数: 17267 | 7 结果4是三个node 5外加一个node 1吧,后面的input跟binary tree 有个bird 关系
【在 s*******r 的大作中提到】 : 250 Count Univalue Subtrees : 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. : For example: : Given binary tree, : 5 : / \ : 1 5 : / \ \ : 5 5 5
| n*******s 发帖数: 17267 | 8 另外,这种题有啥作头,不就是递归。。。吗,为啥要付费? |
|