首页 > 其他 > 详细

LC 1497. Check If Array Pairs Are Divisible by k

时间:2020-06-28 17:17:49      阅读:42      评论:0      收藏:0      [点我收藏+]

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;
    }
};

LC 1497. Check If Array Pairs Are Divisible by k

原文:https://www.cnblogs.com/FEIIEF/p/13203914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!