-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber of Recent Calls.java
47 lines (39 loc) · 1.04 KB
/
Number of Recent Calls.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class RecentCounter {
private ArrayList<Integer> list;
public RecentCounter() {
list = new ArrayList<>();
}
public int ping(int t) {
list.add(t);
int x=t-3000;
int index=list.indexOf(t);
int count=1;
if(index==0){
return count;
}
else{
if(x<t){
for(int i=0;i<list.size()-1;i++){
int y=list.get(i);
if(y>=x && y<=t){
count++;
}
}
}
else{
for(int i=1;i<list.size()-1;i++){
int y=list.get(i);
if(y>=t && y<=x){
count++;
}
}
}
}
return count;
}
}
/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter obj = new RecentCounter();
* int param_1 = obj.ping(t);
*/