# 【leetcode?python】 111. Minimum Depth of Binary Tree

# 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):
depthList=[]
def minDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
self.depthList=[]
if root==None:return 0
self.depthList.append(1)
self.dfs(root)

return min(self.depthList)

def dfs(self,root):

curdepth=self.depthList[-1]

if root.right!=None or root.left!=None:
self.depthList.pop()
else:return

if root.left!=None:
dep=curdepth+1
self.depthList.append(dep)
self.dfs(root.left)
if root.right!=None:
dep=curdepth+1
self.depthList.append(dep)
self.dfs(root.right)

## Leetcode 111. Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree Total Accepted: 114343 Total Submissions:368035 Difficulty: Easy Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le

## Java for LeetCode 111 Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 解题思路:注意minimum depth最后遍历的那个点,left right都必须为null,JAVA实现如下: public int minDepth(TreeNode roo

## 111. Minimum Depth of Binary Tree java solutions

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Subscribe to see which companies asked this question Show Tags Show Similar Problems 1 /**

## letecode [111] - Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7

## 力扣算法题—111.Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7