+ 4
Count the number of leaf nodes.
You are given a tree with N nodes numbered from 0 to N-1.you are also given a node X which you are supposed to delete.you have tell the number of leaf nodes in a tree after deleting the given node.Note that deleting a node deletes all the nodes in its subtree.
4 Respostas
0
int dfs(int node, int parent) {
int res = 0;
for (auto i : v[node])
if (i != deleted && i != parent)
res += dfs(i, node)
if (v[node].size() == 1)
return 1;
else
return res;
Start this function from root of the tree.
vector<int> v[nodes+1];
0
plz give me java code
0
yes it is correct..
0
Java code..?