每日一题:二叉树的最大深度问题
/**
* 返回一棵树的最大深度、
* 测试链接:https://leetcode.com/problems/maximum-depth-of-binary-tree
*/
public class Code03_MaximumDepthOfBinaryTree {
public static class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;
}
public static int maxDepth(TreeNode root){
if (root == null){
return 0;
}
return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
}
}

浙公网安备 33010602011771号