111. Minimum Depth of Binary Tree
https://leetcode.com/problems/minimum-depth-of-binary-tree/
Intuition
We need to find first leaf node at any level.
Level order traversal => BFS - Queue based.
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]
,3 / \ 9 20 / \ 15 7
return its minimum depth = 2.
---Intuition
BFS is right choice and faster for this problem since it exits at first leaf node on first level
DFS is also possible - keep track of depth of each node, and find global minimum depth from all nodes
---
Time - O(n)
Space - O(n)
---
Related problems
104-maximum-depth-of-binary-tree
366-find-leaves-of-binary-tree
---