/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public int findMaxDepth(TreeNode n,intdepth){ int dl=depth,dr=depth; if(n.left!=null) dl=findMaxDepth(n.left,depth+1); if(n.right!=null) dr=findMaxDepth(n.right,depth+1); return Math.max(dl,dr); } public int maxDepth(TreeNode root) { if(root==null) return 0; return findMaxDepth(root,1); } }