Count nodes
\
Given a tree and an integer x, find and return the number of nodes which contains data greater than x.
Input format:
Output Format :
Constraints:
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2:
int getLargeNodeCount(TreeNode<int>* root, int x) {
// Write your code here
int ans=0;
if (root==NULL){
return false;
}
if (root->data>x){
ans=1;
}
for (int i=0;i<root->children.size();i++){
ans+=getLargeNodeCount(root->children[i],x);
}
return ans;
}
Comments
Post a Comment