Skip to content

Commit 92e8246

Browse files
authored
Create Minimum Operations to Exceed Threshold Value I.java
1 parent e3de53f commit 92e8246

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minOperations(int[] nums, int k) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
for (int num : nums) {
5+
map.put(num, map.getOrDefault(num, 0) + 1);
6+
}
7+
PriorityQueue<Integer> pq = new PriorityQueue<>();
8+
pq.addAll(map.keySet());
9+
int count = 0;
10+
while (!pq.isEmpty() && pq.peek() < k) {
11+
count += map.get(pq.poll());
12+
}
13+
return count;
14+
}
15+
}

0 commit comments

Comments
 (0)