Skip to content

Commit 1ccce8a

Browse files
committed
933. Number of Recent Calls
1 parent ef0fa16 commit 1ccce8a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class RecentCounter() {
2+
3+
private val queue = scala.collection.mutable.Queue.empty[Int]
4+
5+
def ping(t: Int): Int = {
6+
queue.addOne(t)
7+
val d = t - 3000
8+
queue.dequeueWhile(_ < d)
9+
queue.size
10+
}
11+
}
12+
13+
/**
14+
* Your RecentCounter object will be instantiated and called as such:
15+
* val obj = new RecentCounter()
16+
* val param_1 = obj.ping(t)
17+
*/
18+
19+
val counter = new RecentCounter()
20+
counter.ping(1)
21+
counter.ping(100)
22+
counter.ping(3001)
23+
counter.ping(3002)

0 commit comments

Comments
 (0)