Skip to content

Commit e338664

Browse files

File tree

5 files changed

+300108
-0
lines changed

5 files changed

+300108
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/zero-matrix-lcci/
14+
15+
https://leetcode.cn/problems/fancy-sequence
16+
1317
https://leetcode.cn/problems/regions-cut-by-slashes/
1418

1519
https://leetcode.cn/problems/minimum-amount-of-time-to-collect-garbage/

fancy-sequence/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export default class Fancy {
2+
#l: number[] = [];
3+
#a = [0n];
4+
#m = [1n];
5+
constructor() {}
6+
7+
append(val: number): void {
8+
this.#l.push(val);
9+
this.#a.push(this.#a.at(-1) as bigint);
10+
this.#m.push(this.#m.at(-1) as bigint);
11+
}
12+
13+
addAll(inc: number): void {
14+
this.#a[this.#a.length - 1] += BigInt(inc);
15+
}
16+
17+
multAll(m: number): void {
18+
this.#a[this.#a.length - 1] *= BigInt(m);
19+
this.#m[this.#m.length - 1] *= BigInt(m);
20+
}
21+
22+
getIndex(idx: number): number {
23+
if (idx >= this.#l.length) return -1;
24+
const m = (this.#m.at(-1) as bigint) / this.#m[idx];
25+
const c = (this.#a.at(-1) as bigint) - this.#a[idx] * m;
26+
27+
return Number((BigInt(this.#l[idx]) * m + c) % BigInt(1e9 + 7));
28+
}
29+
}

0 commit comments

Comments
 (0)