Skip to content

Commit f73b844

Browse files
committed
https://leetcode.cn/problems/longest-uploaded-prefix/
1 parent 029cf34 commit f73b844

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

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

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

13+
https://leetcode.cn/problems/longest-uploaded-prefix/
14+
1315
https://leetcode.cn/problems/find-mode-in-binary-search-tree/
1416

1517
https://leetcode.cn/problems/split-a-string-in-balanced-strings/

longest-uploaded-prefix/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class LUPrefix {
2+
#n: number;
3+
#ptr = 1;
4+
#uploaded: Set<number> = new Set();
5+
constructor(n: number) {
6+
this.#n = n;
7+
}
8+
9+
upload(video: number): void {
10+
this.#uploaded.add(video);
11+
12+
while (this.#ptr <= this.#n && this.#uploaded.has(this.#ptr)) {
13+
++this.#ptr;
14+
}
15+
}
16+
17+
longest(): number {
18+
return this.#ptr - 1;
19+
}
20+
}
21+
export default LUPrefix;

0 commit comments

Comments
 (0)