Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
Why's this leetcode (easy) problem marking me wrong?

Preparing for an interview and practicing some LC. Doing this question:

https://leetcode.com/problems/move-zeroes/

My solution is as follows:

//filter out 0s using filter and includes methods
//check length differnece between initial and filtered array
//difference = num of 0s. push this amount to end of initial array. 
//make new array with dif as size n then fill with 0s and add to initial with spread operator 

var moveZeroes = function(nums) {
    
    let zero = [0];
    let initLength = nums.length;
    nums = nums.filter(num => !zero.includes(num))
    
    let lengthDif = initLength - nums.length
    let zeroArr = new Array(lengthDif)
    zeroArr.fill(0)
    nums = [...nums,...zeroArr]
   
    
};

The debugger shows that nums has a value that is correct after running but LC is saying that my code is incorrect. Am I missing something here or is LC just buggy?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda