LeetCode Records - Question 2244 Minimum Rounds to Complete All Tasks
class Solution {
public int minimumRounds(int[] tasks) {
Map<Integer, Integer> map = new HashMap<>();
for (int task : tasks) {
map.merge(task, 1, Integer::sum);
}
int round = 0;
for (int count : map.values()) {
if (count == 1) {
return -1;
}
int remainder = count % 3;
round += remainder == 0 ? count / 3 : count / 3 + 1;
}
return round;
}
}
- Runtime: 23 ms (Beats: 92.98%)
- Memory: 62.26 MB (Beats: 11.06%)