LeetCode559 N叉树的最大深度

题目:

 

 思路:

直接递归求解最大深度就可以,这里主要记录一下Java中比较获得两个数中最大值的方法。

import java.math.*;
class Solution {
    public int maxDepth(Node root) {
        if(root==null){
            return 0;
        }
        int deep = 0;
        for(int i=0; i<root.children.size(); i++){
            deep = Math.max(deep,maxDepth(root.children.get(i)));
        }
        return deep+1;
    }
}
posted @ 2020-01-18 19:02  sykline  阅读(124)  评论(0编辑  收藏  举报