Skip to content

Commit f6faa99

Browse files
add 933
1 parent 3a81ecc commit f6faa99

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Your ideas/fixes/algorithms are more than welcome!
2929

3030
| # | Title | Solutions | Time | Space | Video | Difficulty | Tag
3131
|-----|----------------|---------------|---------------|---------------|--------|-------------|-------------
32+
|933|[Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_933.java) | O(n) | O(n) | |Easy|
3233
|929|[Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_929.java) | O(n) | O(n) | |Easy|
3334
|922|[Sort Array By Parity II](https://leetcode.com/problems/sort-array-by-parity-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_922.java) | O(n) | O(1) | |Easy|
3435
|917|[Reverse Only Letters](https://leetcode.com/problems/reverse-only-letters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_917.java) | O(n) | O(n) | |Easy|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Deque;
4+
import java.util.LinkedList;
5+
6+
public class _933 {
7+
public static class Solution1 {
8+
public static class RecentCounter {
9+
10+
Deque<Integer> deque;
11+
12+
public RecentCounter() {
13+
deque = new LinkedList<>();
14+
}
15+
16+
public int ping(int t) {
17+
while (!deque.isEmpty() && t - deque.getFirst() > 3000) {
18+
deque.removeFirst();
19+
}
20+
deque.addLast(t);
21+
return deque.size();
22+
}
23+
}
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._933;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _933Test {
10+
private static _933.Solution1.RecentCounter solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _933.Solution1.RecentCounter();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(1, solution1.ping(1));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)