Problem
1 | Given a binary tree, find its minimum depth. |
Solution
Sol 1 recursion
recursively find the smaller counting of child nodes.
if both children exist:
1 | A |
minDepth of A should be 2 (take min)
if only one child exist:
1 | B |
minDepth of B should be 2 (take max)
1 | # Definition for a binary tree node. |
Sol 2 BFS
BFS should be faster in this problem.
1 | # Definition for a binary tree node. |