Skip to content

Commit f9807f4

Browse files
authored
Create 2870-minimum-number-of-operations-to-make-array-empty.kt
1 parent 4a5e9a3 commit f9807f4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
fun minOperations(nums: IntArray): Int {
3+
val count = nums.asIterable().groupingBy { it }.eachCount()
4+
5+
var res = 0
6+
for (c in count.values) {
7+
if (c == 1) return -1
8+
res += (c / 3) + if (c % 3 > 0) 1 else 0 // "Ceil" function
9+
}
10+
11+
return res
12+
}
13+
}

0 commit comments

Comments
 (0)