leetcode-111. Profundidad mínima del árbol binario

tema:

https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/

responder:

Recursión de árbol binario:

 public int minDepth (raíz de TreeNode) {

         si (raíz == nulo) devuelve 0;

       if (root.left == null) return minDepth (root.right) +1;

       if (root.right == null) return minDepth (root.left) +1;

       int leftMinDepth = minDepth (root.left) +1;

       int rightMinDepth = minDepth (root.right) +1;

       return Math.min (leftMinDepth, rightMinDepth);

    }

Supongo que te gusta

Origin blog.csdn.net/wuqiqi1992/article/details/108343623
Recomendado
Clasificación