Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Nullish Coalescing operator in Recursion

I was trying to convert a binary tree to array and I am confused in it. This is the code I am writing:

var maxDepth = function(root) {
    var rc=rc??[];
    if(root==null)
        return ;
    rc.push(root.val);
    maxDepth(root.left);
    maxDepth(root.right);
    return ((rc.length-1)/2)+1;
};

So the problem is that my array always contains 1 element. But according to my understanding , won't after pushing the first element in rc , the nullish coalescing operator will assign the value of rc to the array? Why is it essentially resetting the array?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda