1 int depth = 0; 2 int currentMaxDepth = 0; 3 public int maxDepth(TreeNode root) { 4 if(root == null){ 5 return 0; 6 } 7 8 int leftDepth = 1; 9 int rightDepth = 1; 10 11 leftDepth += maxDepth(root.left); 12 13 rightDepth += maxDepth(root.right); 14 15 if(leftDepth > rightDepth){ 16 return leftDepth; 17 } 18 else{ 19 return rightDepth; 20 } 21 }