Max node of tree
#include <climits>
TreeNode<int>* maxDataNode(TreeNode<int>* root) {
// Write your code here
TreeNode<int>*max=new TreeNode<int>(root->data);
if (max->data<root->data){
max->data=root->data;
max=root;
}
for(int i=0;i<root->children.size();i++){
TreeNode<int>* a=maxDataNode(root->children[i]);
if (a->data>max->data){
max=a;
}
}
return max;
}
Comments
Post a Comment