Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8707e85

Browse files
zhaocchenyanglbme
authored andcommitted
feat: add typescript solution to lcof2 problem: No.042
剑指 Offer II 042. 最近请求次数
1 parent bf27a51 commit 8707e85

File tree

1 file changed

+18
-0
lines changed
  • lcof2/剑指 Offer II 042. 最近请求次数

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class RecentCounter {
2+
stack: Array<number>;
3+
cnt: number;
4+
constructor() {
5+
this.stack = [];
6+
this.cnt = 0;
7+
}
8+
9+
ping(t: number): number {
10+
while (this.stack.length && this.stack[0] + 3000 < t) {
11+
this.cnt--;
12+
this.stack.shift()
13+
}
14+
this.cnt++;
15+
this.stack.push(t);
16+
return this.cnt;
17+
}
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /