559. N 叉树的最大深度c

/**
* Definition for a Node.
* struct Node {
* int val;
* int numChildren;
* struct Node** children;
* };
*/
int maxDepth(struct Node* root) {
if(!root) return 0;
if(root->numChildren==0) return 1;
int max=1;
for(int i=0;i<root->numChildren;i++){
int temp=maxDepth(root->children[i])+1;
if(max<temp) max=temp;
}
return max;
}
结果:

浙公网安备 33010602011771号