Skip to content

Commit 0e764a9

Browse files
authored
Update check-if-array-pairs-are-divisible-by-k.cpp
1 parent 950a53f commit 0e764a9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

C++/check-if-array-pairs-are-divisible-by-k.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ class Solution {
1111
for (const auto& i : arr) {
1212
++count[(i % k + k) % k];
1313
}
14-
for (int i = 0; i < k; ++i) {
15-
if ((!i && count[i] % 2) ||
16-
(i && count[i] != count[k - i])) {
17-
return false;
14+
if (count.count(0) && count[0] % 2) {
15+
return false;
16+
}
17+
for (int i = 1; i < k; ++i) {
18+
if (!count.count(i)) {
19+
continue;
20+
}
21+
if (!(count.count(k - i) && count[i] == count[k - i])) {
22+
return false;
1823
}
1924
}
2025
return true;

0 commit comments

Comments
 (0)