Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c6c91f7

Browse files
committed
Added Number of Recent Calls.java
1 parent 3f19147 commit c6c91f7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Easy/Number of Recent Calls.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class RecentCounter {
2+
Queue<Integer> queue;
3+
int limit;
4+
public RecentCounter() {
5+
queue = new LinkedList<>();
6+
limit = 3000;
7+
}
8+
9+
public int ping(int t) {
10+
queue.add(t);
11+
while (!queue.isEmpty() && ((t - queue.peek()) > limit)) {
12+
queue.remove();
13+
}
14+
return queue.size();
15+
}
16+
}
17+
18+
/**
19+
* Your RecentCounter object will be instantiated and called as such:
20+
* RecentCounter obj = new RecentCounter();
21+
* int param_1 = obj.ping(t);
22+
*/

0 commit comments

Comments
 (0)