NC_13_MAX_DEPTH

package org.example.interview.practice;

/**
 * @author xianzhe.ma
 * @date 2021/11/4
 */

public class NC_13_MAX_DEPTH {

    public int maxDepth (TreeNode root) {
        // write code here
        if (root == null) {
            return 0;
        }

        int left = maxDepth(root.left);
        int right = maxDepth(root.right);

        return 1 + Math.max(left, right);
    }

    public static class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }
}

 

posted on 2022-02-10 15:45  MaXianZhe  阅读(18)  评论(0编辑  收藏  举报

导航