Skip to content

Commit 4ff9abb

Browse files
add 2899
1 parent 8c1911f commit 4ff9abb

File tree

2 files changed

+29
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src/main/java/com/fishercoder/solutions/thirdthousand

2 files changed

+29
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| 2965 | [Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2965.java) | | Easy |
77
| 2942 | [Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2942.java) | | Easy |
88
| 2937 | [Make Three Strings Equal](https://leetcode.com/problems/make-three-strings-equal/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2937.java) | | Easy |
9+
| 2899 | [Last Visited Integers](https://leetcode.com/problems/last-visited-integers/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2899.java) | | Easy |
910
| 2894 | [Divisible and Non-divisible Sums Difference](https://leetcode.com/problems/divisible-and-non-divisible-sums-difference/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2894.java) | | Easy |
1011
| 2873 | [Maximum Value of an Ordered Triplet I](https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2873.java) | | Easy |
1112
| 2869 | [Minimum Operations to Collect Elements](https://leetcode.com/problems/minimum-operations-to-collect-elements/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2869.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2899 {
7+
public static class Solution1 {
8+
public List<Integer> lastVisitedIntegers(int[] nums) {
9+
List<Integer> ans = new ArrayList<>();
10+
List<Integer> seen = new ArrayList<>();
11+
int k = 1;
12+
for (int num : nums) {
13+
if (num != -1) {
14+
seen.add(num);
15+
k = 1;
16+
} else {
17+
if (k <= seen.size()) {
18+
ans.add(seen.get(seen.size() - k));
19+
} else {
20+
ans.add(-1);
21+
}
22+
k++;
23+
}
24+
}
25+
return ans;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)