deno.land / x / masx200_leetcode_test@10.6.5 / p0NxJO / 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
import { Heap } from "../deps.ts";import { sum as sumarray } from "../richest-customer-wealth/sum.ts";
function magicTower(nums: number[]): number { const heap = new Heap<number>((a, b) => a - b); if (sumarray(nums) < 0) { return -1; }
let ans = 0;
let sum = 1; for (const num of nums) { sum += num; if (num < 0) { heap.insert(num); } if (sum <= 0 && !heap.isEmpty()) { const val = heap.pop() ?? 0; sum -= val; ans++; } } return ans;}export default magicTower;
masx200_leetcode_test
leetcode题解和一些测试工具
DocumentationDocumentation
GitHub Repositorymasx200/leetcode-test
GitHub Stars
4

Version Info

Tagged at
4 months ago