Skip to content

Commit 3489b92

Browse files
committed
Add Number of Recent Call
1 parent 5082347 commit 3489b92

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Problems:https://leetcode.com/problems/number-of-recent-calls/
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace LeetCode {
6+
public class RecentCounter {
7+
8+
Queue<int> requests;
9+
10+
public RecentCounter() {
11+
requests = new Queue<int>();
12+
}
13+
14+
public int Ping(int t) {
15+
requests.Enqueue(t);
16+
while(t - requests.Peek() > 3000) {
17+
requests.Dequeue();
18+
}
19+
20+
return requests.Count();
21+
}
22+
}
23+
24+
/**
25+
* Your RecentCounter object will be instantiated and called as such:
26+
* RecentCounter obj = new RecentCounter();
27+
* int param_1 = obj.Ping(t);
28+
*/
29+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ LeetCode C# solutions
66
|**344**| **[Reverse String](https://leetcode.com/problems/reverse-string/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/344-ReverseString.cs)** | **Easy** |
77
|**509**| **[Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/509-FibonacciNumber.cs)** | **Easy** |
88
|**682**| **[Baseball Game](https://leetcode.com/problems/baseball-game/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/682-BaseballGame.cs)** | **Easy** |
9-
|**1432**| **[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1431-KidsWithGreatestNumberofCandies.cs)** | **Easy** |
9+
|**933**| **[Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/933-NumberofRecentCalls.cs)** | **Easy** |
10+
|**1431**| **[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1431-KidsWithGreatestNumberofCandies.cs)** | **Easy** |

0 commit comments

Comments
 (0)