111. Minimum Depth of Binary Tree*
2016-12-22 19:54
204 查看
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.
My code:
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
My code:
# 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 not root: return 0 return max(self.maxDepth(root.left),self.maxDepth(root.right))+1总结:要注意如果左右节点一个为空,要选大的。没有清楚概念,看了参考答案。但是思路和代码是对的。
相关文章推荐
- 【LeetCode 111_二叉树_遍历】Minimum Depth of Binary Tree
- leetcode:111 Minimum Depth of Binary Tree-每日编程第三十题
- leetcode || 111、Minimum Depth of Binary Tree
- LeetCode(111) Minimum Depth of Binary Tree
- Leetcode 111, Minimum Depth of Binary Tree
- leetcode111~Minimum Depth of Binary Tree
- 【Leetcode-easy-111】Minimum Depth of Binary Tree
- 111-e-Minimum Depth of Binary Tree
- LeetCode(111) Minimum Depth of Binary Tree
- leetcode 111 —— Minimum Depth of Binary Tree
- leetcode 111: Minimum Depth of Binary Tree
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
- Leetcode[111]-Minimum Depth of Binary Tree
- leetCode #111 Minimum Depth of Binary Tree
- LeetCode111 Minimum Depth of Binary Tree
- [leetcode-111]Minimum Depth of Binary Tree(C语言)
- Leetcode 111 Minimum Depth of Binary Tree
- LeetCode111—Minimum Depth of Binary Tree
- leetcode-111-Minimum Depth of Binary Tree
- [LeetCode-111] Minimum Depth of Binary Tree (二叉树最小深度)