LeetCode刷题笔记(104,二叉树的最大深度,Easy)

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        int lchildhigh = maxDepth(root.left);
        int rchildhigh = maxDepth(root.right);
        return 1+Math.max(lchildhigh,rchildhigh);
    }
}

 

你可能感兴趣的:(LeetCode刷题笔记(104,二叉树的最大深度,Easy))