forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2244.java
31 lines (29 loc) · 916 Bytes
/
_2244.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _2244 {
public static class Solution1 {
public int minimumRounds(int[] tasks) {
Map<Integer, Integer> map = new HashMap<>();
for (int task : tasks) {
map.put(task, map.getOrDefault(task, 0) + 1);
}
int rounds = 0;
for (int task : map.keySet()) {
int count = map.get(task);
if (count == 2 || count == 3) {
rounds++;
} else if (count == 1) {
return -1;
} else {
if (count % 3 == 0) {
rounds += count / 3;
} else {
rounds += (count / 3 + 1);
}
}
}
return rounds;
}
}
}