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

290
Visualizações
Leetcode problems solution throwing error please assist

Leetcode problems solution throwing error please assist MY CODE RUNS JUST FINE I DONT GET WHERE THE ISSUE IS COMMING FROM PLS ASSIST ME SIR

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself. example

Example one
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2:

Input: l1 = [0], l2 = [0]
Output: [0]



MY CODE

var addTwoNumbers = function(l1, l2) {

   var alpha1 = "" 
   var alpha2 = ""
   var arr = []


 // Looping through first list l1

   for(var i = 0; i< l1.length; i++){
    alpha1 = l1[i]+alpha1

    // converting   l1 to string and setting it to ALPHA 1 
   }

   // Looping through second  list L2
   for(var i = 0; i< l2.length; i++){
    alpha2 = l2[i]+alpha2

    // converting   l2 to string and setting it to ALPHA 2 
   }
   // Coverting alpha1 and apha2 to intergets and making their sum to a new variable string "New"
  var New = parseInt(alpha1) +  parseInt(alpha2)
   New = New + ""
 
  for(var i=0;i<New.length; i++){
// Pushing the New variable is reverse order to arr and also converting it back to interger
arr.push(parseInt(New[New.length-i-1]))

  }
  // Returning the array
  return arr
};
addTwoNumbers([9,9,9,9,9,9,9],[9,9,9,9])

MY CODE WORKS JUST FINE ON CONSOLE

THE ERROR

Line 51 in solution.js
             throw new TypeError(__serialize__(ret) + " is not valid value for the expected return type ListNode");
             ^
TypeError: [null,null,null] is not valid value for the expected return type ListNode
    Line 51: Char 20 in solution.js (Object.<anonymous>)
    Line 16: Char 8 in runner.js (Object.runner)
    Line 35: Char 26 in solution.js (Object.<anonymous>)
    Line 1251: Char 30 in loader.js (Module._compile)
    Line 1272: Char 10 in loader.js (Object.Module._extensions..js)
    Line 1100: Char 32 in loader.js (Module.load)
    Line 962: Char 14 in loader.js (Function.Module._load)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    Line 17: Char 47 in run_main_module.js
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem description specifies that each number may have up to 100 digits. The largest integer which can be accurately represented in Javascript has 16 digits. So your program isn't going to work for lots of possible inputs, as you will see if you test it with larger arrays.

about 4 years ago · Juan Pablo Isaza Relatório
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