+ 1
How to convert my output as a linked list
var addTwoNumbers = function(l1, l2) { let strL1=""; for(let i=l1.length-1;i>=0;i--){ strL1+=l1[i]; } let numL1=Number(strL1); let strL2=""; for(let i=l2.length-1;i>=0;i--){ strL2+=l2[i]; } let numL2=Number(strL2); let result = (numL1 + numL2).toString(); let rev=[]; for(let i=result.length-1;i>=0;i--){ rev.push(result[i]); } console.log(rev.map(Number));//How to convert it to linked list }; addTwoNumbers([9,9,9,9,9,9,9], [9,9,9,9]);
5 Respuestas
0
This is some tutorial about linked list in java script
https://www.google.com/amp/s/www.freecodecamp.org/news/implementing-a-linked-list-in-javascript/amp/
0
It's in array format
0
How you output need to look like?
Your output is [8, 9, 9, 9, 0, 0, 0, 1], but sololearn compile it as 8,9,9,9,0,0,0,1
If you test your code somewere else you will see normal array