deno.land / x / masx200_leetcode_test@10.6.5 / minimum-number-of-operations-to-move-all-balls-to-each-box / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default function minOperations(boxes: string): number[] { const dp: number[] = Array(boxes.length).fill(0);
let right = 0; for (const [index, value] of Array.prototype.entries.call(boxes)) { if (value === "1") { dp[0] += index; right += 1; } } let left = 0; for (let j = 1; j < boxes.length; j++) { if (boxes[j - 1] === "1") { left += 1; right -= 1; } dp[j] = dp[j - 1] - right + left; } return dp;}
masx200_leetcode_test

Version Info

Tagged at
a year ago