Skip to content

Commit 98d5bd8

Browse files
committed
feat: update solutions to leetcode problem: No.0933. Number of Recent Calls
1 parent 6389ba1 commit 98d5bd8

File tree

4 files changed

+79
-11
lines changed

4 files changed

+79
-11
lines changed

solution/0900-0999/0933.Number of Recent Calls/README.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ recentCounter.ping(3002); // requests = [1, <strong>100</strong>, <strong>3001<
4646
<li>至多调用 <code>ping</code> 方法 <code>10<sup>4</sup></code> 次</li>
4747
</ul>
4848

49-
5049
## 解法
5150

5251
<!-- 这里可写通用的实现逻辑 -->
@@ -65,13 +64,12 @@ recentCounter.ping(3002); // requests = [1, <strong>100</strong>, <strong>3001<
6564
class RecentCounter:
6665

6766
def __init__(self):
68-
self.q = []
69-
67+
self.q = collections.deque()
7068

7169
def ping(self, t: int) -> int:
7270
self.q.append(t)
7371
while self.q[0] < t - 3000:
74-
self.q.pop(0)
72+
self.q.popleft()
7573
return len(self.q)
7674

7775

@@ -109,6 +107,32 @@ class RecentCounter {
109107
*/
110108
```
111109

110+
### **JavaScript**
111+
112+
```js
113+
var RecentCounter = function () {
114+
this.q = [];
115+
};
116+
117+
/**
118+
* @param {number} t
119+
* @return {number}
120+
*/
121+
RecentCounter.prototype.ping = function (t) {
122+
this.q.push(t);
123+
while (this.q[0] < t - 3000) {
124+
this.q.shift();
125+
}
126+
return this.q.length;
127+
};
128+
129+
/**
130+
* Your RecentCounter object will be instantiated and called as such:
131+
* var obj = new RecentCounter()
132+
* var param_1 = obj.ping(t)
133+
*/
134+
```
135+
112136
### **...**
113137

114138
```

solution/0900-0999/0933.Number of Recent Calls/README_EN.md

+28-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ recentCounter.ping(3002); // requests = [1, <u>100</u>, <u>3001</u>, <u>3002</u
4242
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>ping</code>.</li>
4343
</ul>
4444

45-
4645
## Solutions
4746

4847
<!-- tabs:start -->
@@ -53,13 +52,12 @@ recentCounter.ping(3002); // requests = [1, <u>100</u>, <u>3001</u>, <u>3002</u
5352
class RecentCounter:
5453

5554
def __init__(self):
56-
self.q = []
57-
55+
self.q = collections.deque()
5856

5957
def ping(self, t: int) -> int:
6058
self.q.append(t)
6159
while self.q[0] < t - 3000:
62-
self.q.pop(0)
60+
self.q.popleft()
6361
return len(self.q)
6462

6563

@@ -95,6 +93,32 @@ class RecentCounter {
9593
*/
9694
```
9795

96+
### **JavaScript**
97+
98+
```js
99+
var RecentCounter = function () {
100+
this.q = [];
101+
};
102+
103+
/**
104+
* @param {number} t
105+
* @return {number}
106+
*/
107+
RecentCounter.prototype.ping = function (t) {
108+
this.q.push(t);
109+
while (this.q[0] < t - 3000) {
110+
this.q.shift();
111+
}
112+
return this.q.length;
113+
};
114+
115+
/**
116+
* Your RecentCounter object will be instantiated and called as such:
117+
* var obj = new RecentCounter()
118+
* var param_1 = obj.ping(t)
119+
*/
120+
```
121+
98122
### **...**
99123

100124
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var RecentCounter = function () {
2+
this.q = [];
3+
};
4+
5+
/**
6+
* @param {number} t
7+
* @return {number}
8+
*/
9+
RecentCounter.prototype.ping = function (t) {
10+
this.q.push(t);
11+
while (this.q[0] < t - 3000) {
12+
this.q.shift();
13+
}
14+
return this.q.length;
15+
};
16+
17+
/**
18+
* Your RecentCounter object will be instantiated and called as such:
19+
* var obj = new RecentCounter()
20+
* var param_1 = obj.ping(t)
21+
*/

solution/0900-0999/0933.Number of Recent Calls/Solution.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
class RecentCounter:
22

33
def __init__(self):
4-
self.q = []
5-
4+
self.q = collections.deque()
65

76
def ping(self, t: int) -> int:
87
self.q.append(t)
98
while self.q[0] < t - 3000:
10-
self.q.pop(0)
9+
self.q.popleft()
1110
return len(self.q)
1211

1312

0 commit comments

Comments
 (0)