解题思路:递归算法
/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/import java.lang.Math;public class Solution {
public int TreeDepth(TreeNode pRoot)
{ if(pRoot == null){ return 0;
} int left = TreeDepth(pRoot.left); int right = TreeDepth(pRoot.right); return Math.max(left, right) + 1;
}
}下载本文