104. 二叉树的最大深度

题目链接:

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 }

 

posted @ 2019-07-25 14:38  王爷爱吃秋刀鱼  阅读(118)  评论(0编辑  收藏  举报