3249. Count the Number of Good Nodes
There is an undirected tree with
nnodes labeled from0ton - 1, and rooted at node0. You are given a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [ai, bi]indicates that there is an edge between nodesaiandbiin the tree.A node is good if all the subtrees rooted at its children have the same size.
Return the number of good nodes in the given tree.
A subtree of
treeNameis a tree consisting of a node intreeNameand all of its descendants.
1 | class Solution { |