250 Count Univalue Subtrees
250. Count Univalue Subtrees
1. Question
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,
return4
.
2. Implementation
(1) DFS + post order traversal
3. Time & Space Complexity
DFS: 时间复杂度是O(n), 空间复杂度是O(h)
Last updated