deno.land / x / masx200_leetcode_test@10.6.5 / add-to-array-form-of-integer / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function addToArrayForm(A: number[], K: number): number[] { const res = [];
let i = A.length - 1, carry = 0;
while (i >= 0 || K != 0) { const x = i >= 0 ? A[i] : 0;
const y = K != 0 ? K % 10 : 0;
const sum = x + y + carry;
res.push(sum % 10);
carry = Math.floor(sum / 10);
i--;
K = Math.floor(K / 10); } if (carry) { res.push(carry); } return res.reverse();}export default addToArrayForm;
masx200_leetcode_test

Version Info

Tagged at
a year ago