题目链接:
https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
解题思路:
1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */ 10 class Solution { 11 int result = 0; 12 public int maxDepth(TreeNode root) { 13 14 if (root == null) { 15 return 0; 16 } 17 return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; 18 19 } 20 }