//递归求解-三部曲
//第一次一次AC,2020/01/04 加油
public class Solution {
public int TreeDepth(TreeNode root) {
//1、边界条件
int result=0;
if(root==null){
return 0;
}else{
result++;
}
//2、每一步作了什么
int leftDepth=TreeDepth(root.left);
int rightDepth=TreeDepth(root.right);
if(leftDepth>rightDepth){
//3、返回值是啥
return result+leftDepth;
}else{
return result+rightDepth;
}
}
}
京公网安备 11010502036488号