[勇者闯LeetCode] 104. Maximum Depth of Binary Tree
2017-04-09 15:51
387 查看
[勇者闯LeetCode] 104. Maximum Depth of Binary Tree
Description
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Information
Tags: Tree | Depth-first SearchDifficulty: Easy
Solution
采用递归:二叉树的最大深度=max(左子树的最大深度,右子树的最大深度)+1# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ if root is None: return 0 else: return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
相关文章推荐
- LeetCode 545. Boundary of Binary Tree
- [勇者闯LeetCode] 11. Container With Most Water
- [Leetcode] binary tree 右视问题
- [勇者闯LeetCode] 70. Climbing Stairs
- [勇者闯LeetCode] 142. Linked List Cycle II
- leetcode 543. Diameter of Binary Tree
- LeetCode 111. Minimum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode 104. Maximum Depth of Binary Tree
- [勇者闯LeetCode] 13. Roman to Integer
- [LeetCode]104. Maximum Depth of Binary Tree
- [勇者闯LeetCode] 110. Balanced Binary Tree
- Invert Binary Tree -- leetcode
- [leetcode: Python] 111. Minimum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- LEETCODE —— Binary Tree的3 题 —— 3种非Recursive遍历
- [LeetCode]111. Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [勇者闯LeetCode] 215. Kth Largest Element in an Array
- [leetcode] 111. Minimum Depth of Binary Tree