1497.cpp (423B)
1 class Solution { 2 public: 3 bool canArrange(const vector<int> &arr, int k) const { 4 static int count[100000]; 5 6 memset(count, 0x00, sizeof(count)); 7 for (const int n : arr) 8 count[((n % k) + k) % k]++; 9 10 if (count[0] % 2 == 1) return false; 11 for (int i = 1; i <= k / 2; i++) { 12 if (count[i] != count[k - i]) return false; 13 } 14 15 return true; 16 } 17 };