publicclassTest38{publicstaticvoidmain(String[] args){}publicintTreeDepth(TreeNode root){returndepth(root,0);}privateintdepth(TreeNode root,int i){if(root == null){return0;}
i = i +1;
TreeNode tmp = root;int left =0;int right =0;if(tmp.left != null){
left =depth(tmp.left, i);}if(tmp.right != null){
right =depth(tmp.right, i);}return Math.max(i, Math.max(left, right));}publicclassTreeNode{int val =0;
TreeNode left = null;
TreeNode right = null;publicTreeNode(int val){this.val = val;}}}//其他方法/**
public class Solution {
public int TreeDepth(TreeNode root) {
if(root==null){
return 0;
}
int nLelt=TreeDepth(root.left);
int nRight=TreeDepth(root.right);
return nLelt>nRight?(nLelt+1):(nRight+1);
}
}
*/