Skip to content

Commit 5b7450b

Browse files
authored
Create 1497. Check If Array Pairs Are Divisible by k (#600)
2 parents 89d1428 + ac7c975 commit 5b7450b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool canArrange(vector<int>& arr, int k) {
4+
vector<int> freq(k,0);
5+
for(auto& it: arr){
6+
int rem = it % k;
7+
if(rem < 0) rem += k;
8+
freq[rem]++;
9+
}
10+
11+
if(freq[0] % 2) return false;
12+
13+
for(int i=1; i<=k/2; i++){
14+
if(freq[i] != freq[k-i]) return false;
15+
}
16+
return true;
17+
}
18+
};
19+
auto speedup = []()
20+
{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0;
21+
}();

0 commit comments

Comments
 (0)