Skip to content

Commit 8cac237

Browse files
add 2869
1 parent 569127e commit 8cac237

File tree

2 files changed

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

2 files changed

+24
-0
lines changed

Diff for: paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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 |
99
| 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 |
10+
| 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 |
1011
| 2864 | [Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2864.java) | | Easy |Greedy
1112
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2839.java) | | Easy |
1213
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2833.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Set;
6+
7+
public class _2869 {
8+
public static class Solution1 {
9+
public int minOperations(List<Integer> nums, int k) {
10+
Set<Integer> set = new HashSet<>();
11+
for (int i = 1; i <= k; i++) {
12+
set.add(i);
13+
}
14+
for (int i = nums.size() - 1; i >= 0; i--) {
15+
set.remove(nums.get(i));
16+
if (set.size() == 0) {
17+
return nums.size() - i;
18+
}
19+
}
20+
return -1;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)