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
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.