LC 1497. Check If Array Pairs Are Divisible by k

link

class Solution {
public:
    bool canArrange(vector<int>& arr, int k) {
        unordered_map<int,int> cnt;
        for(int i:arr){
            cnt[(i%k+k)%k]++;
        }
        if(cnt[0]&1) return false;
        for(int i=1;i<k;i++) if(cnt[i]!=cnt[k-i]) return false;
        return true;
    }
};
原文地址:https://www.cnblogs.com/FEIIEF/p/13203914.html