在力扣中使用reverse 提示 reverse not a function 于是用了下面的方法反转数组,但是还是报错
var addTwoNumbers = function (l1, l2) {
let arr1 = []
debugger
for (let i = l1.length; i > 0; i--) {
arr1.push(l1[i - 1])
}
let arr2 = []
for (let j = l2.length; j > 0; j--) {
arr2.push(l2[j - 1])
}
let a = Number(arr1.join(''))
let b = Number(arr2.join(''))
let c = a + b
let d = c.toString().split('').reverse()
return d.map(Number)
}
console.log(addTwoNumbers([2, 4, 3], [5, 6, 4]))
报错
Line 44 in solution.js
throw new TypeError(__serialize__(ret) + " is not valid value for the expected return type ListNode");
^
TypeError: [0] is not valid value for the expected return type ListNode
Line 44: Char 20 in solution.js (Object.<anonymous>)
Line 16: Char 8 in runner.js (Object.runner)
Line 28: Char 26 in solution.js (Object.<anonymous>)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47