File tree 2 files changed +47
-0
lines changed
lcof2/剑指 Offer II 042. 最近请求次数
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -213,6 +213,32 @@ RecentCounter.prototype.ping = function (t) {
213
213
*/
214
214
```
215
215
216
+ #### Swift
217
+
218
+ ``` swift
219
+ class RecentCounter {
220
+ private var q: [Int ]
221
+
222
+ init () {
223
+ q = []
224
+ }
225
+
226
+ func ping (_ t : Int ) -> Int {
227
+ q.append (t)
228
+ while q.first ! < t - 3000 {
229
+ q.removeFirst ()
230
+ }
231
+ return q.count
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Your RecentCounter object will be instantiated and called as such:
237
+ * let obj = RecentCounter()
238
+ * let param_1 = obj.ping(t)
239
+ */
240
+ ```
241
+
216
242
<!-- tabs:end -->
217
243
218
244
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ class RecentCounter {
2
+ private var q : [ Int ]
3
+
4
+ init ( ) {
5
+ q = [ ]
6
+ }
7
+
8
+ func ping( _ t: Int ) -> Int {
9
+ q. append ( t)
10
+ while q. first! < t - 3000 {
11
+ q. removeFirst ( )
12
+ }
13
+ return q. count
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Your RecentCounter object will be instantiated and called as such:
19
+ * let obj = RecentCounter()
20
+ * let param_1 = obj.ping(t)
21
+ */
You can’t perform that action at this time.
0 commit comments