FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/number-of-recent-calls.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
number-of-recent-calls.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
20 lines (15 loc) · 410 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
number-of-recent-calls.py
Copy path
File metadata and controls
20 lines (15 loc) · 410 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Time: O(1) on average
# Space: O(w), w means the size of the last milliseconds.
import
collections
class
RecentCounter
(
object
):
def
__init__
(
self
):
self
.
__q
=
collections
.
deque
()
def
ping
(
self
,
t
):
"""
:type t: int
:rtype: int
"""
self
.
__q
.
append
(
t
)
while
self
.
__q
[
0
]
<
t
-
3000
:
self
.
__q
.
popleft
()
return
len
(
self
.
__q
)
Back
|
FazBrowse Home
|
New Git URL