算法:递归
原理:递归遍历二叉树,从底向上计数
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public int maxDepth(TreeNode root) { if (null == root) { return 0; } int left = maxDepth(root.left); int right = maxDepth(root.right); return (left > right ? left+1 : right+1); } }
[LeetCode]Maximum Depth of Binary Tree,布布扣,bubuko.com
[LeetCode]Maximum Depth of Binary Tree
原文地址:http://blog.csdn.net/yeweiouyang/article/details/36216093