我的 leetcode 出現錯誤,我不知道為什么:
var addTwoNumbers = function(l1, l2) {
let newL1 = []
let newL2 = []
let answer = []
for(let i = 0; i < l1.length; i ) {
newL1[i] = l1[l1.length - 1 - i]
}
for(let i = 0; i < l2.length; i ) {
newL2[i] = l2[l2.length - 1 - i]
}
let num = parseInt(newL1.toString().replace(/,/g, '')) parseInt(newL2.toString().replace(/,/g, ''))
let rawAnswer = (num.toString().split(""))
for(let i=0; i < rawAnswer.length; i ) {
answer[i] = parseInt(rawAnswer[i])
}
return answer
}
錯誤:
Line 45 in solution.js
throw new TypeError(__serialize__(ret) " is not valid value for the expected return type ListNode");
^
TypeError: null is not valid value for the expected return type ListNode
Line 45: Char 20 in solution.js (Object.<anonymous>)
Line 16: Char 8 in runner.js (Object.runner)
Line 29: 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
挑戰說明:
給定兩個表示兩個非負整數的非空鏈表。這些數字以相反的順序存盤,它們的每個節點都包含一個數字。將兩個數字相加并將總和作為鏈表回傳。您可以假設這兩個數字不包含任何前導零,除了數字 0 本身。
例子:
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 465 = 807.
我不知道為什么我會收到這個錯誤,但我知道我正在做一些 leetcode 不喜歡的事情。
謝謝
uj5u.com熱心網友回復:
描述如下: return the sum as a linked list
您正在執行兩個parseInt并回傳總和(即一個數字),但它應該回傳一個鏈表,該鏈表由串列的頭部(第一個ListNode物件)定義。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/354514.html
標籤:javascript 数组 节点
