3249. Count the Number of Good Nodes
There is an undirected tree with
n
nodes labeled from0
ton - 1
, and rooted at node0
. You are given a 2D integer arrayedges
of lengthn - 1
, whereedges[i] = [ai, bi]
indicates that there is an edge between nodesai
andbi
in 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
treeName
is a tree consisting of a node intreeName
and all of its descendants.
1 | class Solution { |