publicclassTreeNode{ int val = 0; TreeNode left = null; TreeNode right = null; publicTreeNode(int val){ this.val = val; } }
publicclassSolution{ publicintTreeDepth(TreeNode root){ if(root==null){ return0; } int left = TreeDepth(root.left)+1; int right = TreeDepth(root.right)+1; int res = Math.max(left,right); return res; } }