/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public int maxDepth(TreeNode root) { if(root == null) return 0; return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; } }
相关文章
- 12-13Leetcode_114_Flatten Binary Tree to Linked List
- 12-13[LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal_Medium tag: Tree Traversal
- 12-1319.3.5 [LeetCode 104] Maximum Depth of Binary Tree
- 12-13104.Maximum Depth of Binary Tree
- 12-13Maximum Depth of Binary Tree
- 12-13[LeetCode] Maximum Depth of Binary Tree 二叉树的最大深度
- 12-13maximum-depth-of-binary-tree
- 12-13Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
- 12-13LeetCode Binary Tree Preorder Traversal 先根遍历
- 12-13【LeetCode】297. Serialize and Deserialize Binary Tree 解题报告(Python)