leetcode --- js版本程序员

leetcode-tree-111- Minimum Depth

2019-06-13  本文已影响0人  石头说钱

题目:Balanced Binary Tree

Minimum Depth of Binary Tree

    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))
}

上一篇 下一篇

猜你喜欢

热点阅读