2870.cpp (362B)
1 class Solution { 2 public: 3 int minOperations(const vector<int> &nums) const { 4 unordered_map<int, int> count; 5 for (const int n : nums) 6 count[n]++; 7 8 int res = 0; 9 for (const auto [_, cnt] : count) { 10 if (cnt == 1) return -1; 11 res += ceil((double)cnt / 3); 12 } 13 return res; 14 } 15 };