题解 | #二叉树的最大深度,递归#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
int maxDepth = 0 ;
public int maxDepth (TreeNode root) {
if(root == null) return 0 ;
return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1 ;
}
}
一个菜鸟的算法刷题记录 文章被收录于专栏
分享一个菜鸟的成长记录
查看10道真题和解析
深信服公司福利 731人发布