Skip to content

Commit bfa43a4

Browse files
solves Number Of Recent Calls
1 parent 1cd3a33 commit bfa43a4

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
| 922 | [Sort Array by Parity II](https://leetcode.com/problems/sort-array-by-parity-ii) | [![Java](assets/java.png)](src/SortArrayByParityII.java) |
252252
| 925 | [Long Pressed Name](https://leetcode.com/problems/long-pressed-name) | [![Java](assets/java.png)](src/LongPressedName.java) |
253253
| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) |
254-
| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | |
254+
| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) |
255255
| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | |
256256
| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | |
257257
| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | |

src/NumberOfRecentCalls.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class NumberOfRecentCalls {
2+
class RecentCounter {
3+
private Node head;
4+
private Node tail;
5+
private int size = 0;
6+
7+
public int ping(int t) {
8+
size++;
9+
if (head == null) {
10+
head = new Node(t);
11+
tail = head;
12+
} else {
13+
tail.next = new Node(t);
14+
tail = tail.next;
15+
}
16+
while (head.val < t - 3000) {
17+
head = head.next;
18+
size--;
19+
}
20+
return size;
21+
}
22+
23+
private class Node {
24+
int val;
25+
Node next;
26+
27+
Node(final int val) {
28+
this.val = val;
29+
}
30+
}
31+
}
32+
}

src/TeemoAttacking.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
public class TeemoAttacking {
2-
public static void main(String[] args) {
3-
System.out.println(findPoisonedDuration(new int[] {1, 2}, 2));
4-
}
5-
6-
public static int findPoisonedDuration(int[] timeSeries, int duration) {
2+
public int findPoisonedDuration(int[] timeSeries, int duration) {
73
int poisonDuration = 0;
84
for (int i = 0, current = timeSeries[0] - 1 ; i < timeSeries.length; i++) {
95
poisonDuration += duration - Math.max(0, Math.max(current, timeSeries[i] - 1) - timeSeries[i] + 1);

0 commit comments

Comments
 (0)