leetcode-tree-111- Minimum Depth
2019-06-13 本文已影响0人
石头说钱
题目:Balanced Binary Tree
Minimum Depth of Binary Tree
- Example 1
Given the following tree [3,9,20,null,null,15,7]:
3
/ \
9 20
/ \
15 7
minimum depth = 2
解法
function minimumDepth(root){
if(!root) return 0;
if(!root.left) return 1 + minimumDepth(root.right)
if(!root.right) return 1 + minimumDepth(root.left)
return 1+ Math.min(minimumDepth(root.left,root.right))
}