<jupyter_start><jupyter_text>111. Minimum Depth of Binary Tree  ContentGiven 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:&nbsp;A leaf is a node with no children.&nbsp;Example 1:Input: root = [3,9,20,null,null,15,7]Output: 2Example 2:Input: root = [2,null,3,null,4,null,5,null,6]Output: 5&nbsp;Constraints:	The number of nodes in the tree is in the range [0, 105].	-1000 &lt;= Node.val &lt;= 1000  Difficulty: Easy, AC rate: 40.7% Question Tags:- Tree- Depth-First Search- Breadth-First Search- Binary Tree Links: 🎁 [Question Detail](https://leetcode.com/problems/minimum-depth-of-binary-tree/description/) | 🎉 [Question Solution](https://leetcode.com/problems/minimum-depth-of-binary-tree/solution/) | 💬 [Question Discussion](https://leetcode.com/problems/minimum-depth-of-binary-tree/discuss/?orderBy=most_votes) Hints:  Sample Test Case[3,9,20,null,null,15,7] ---What's your idea?BFS---<jupyter_code>from queue import Queue

# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def minDepth(self, root: TreeNode) -> int:
        if root is None:
            return 0
        
        q = Queue()
        root.val = 1
        q.put(root)
        while not q.empty():
            n = q.get()
            if not n.left and not n.right:
                return n.val
            if n.left:
                n.left.val = n.val + 1
                q.put(n.left)
            if n.right:
                n.right.val = n.val + 1
                q.put(n.right)
s = Solution()

n7 = TreeNode(7)
n15 = TreeNode(15)
n20 = TreeNode(20, n15, n7)
n9 = TreeNode(9)
n3 = TreeNode(3, n9, n20)
s.minDepth(n3)
n6 = TreeNode(6)
n5 = TreeNode(5, None, n6)
n4 = TreeNode(4, None, n5)
n3 = TreeNode(3, None, n4)
n2 = TreeNode(2, None, n3)
s.minDepth(n2)
s.minDepth(None)
n = TreeNode(0)
s.minDepth(n)
import sys, os; sys.path.append(os.path.abspath('..'))
from submitter import submit
submit(111)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1344731977818854, 'fraction_numerical': 0.03974121996303143, 'mean_word_length': 2.900900900900901, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '517710', 'license': 'MIT', 'n_tokens_mistral': 831, 'n_tokens_neox': 766, 'n_words': 213, 'path': '101-150/111.minimum-depth-of-binary-tree.ipynb', 'repo_name': 'Sorosliu1029/LeetCode', 'size': '2164'}