树形bp,递归条件:是不是有子节点,如果有:返回子树中,最大的深度
public int maxDepth(Node root) {
return process(root);
}
public int process(Node root){
if(root==null){
return 0;
}
int max = 0;
for(Node cur:root.children){
max = Math.max(max,process(cur));
}
return max+1;
}
}
可以参考,二叉树的最大深度