1497. Check If Array Pairs Are Divisible by k
https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/
Given an array of integers arr
of even length n
and an integer k
.
We want to divide the array into exactly n / 2
pairs such that the sum of each pair is divisible by k
.
Return True If you can find a way to do that or False otherwise.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
arr.length == n
1 <= n <= 10^5
n
is even.-10^9 <= arr[i] <= 10^9
1 <= k <= 10^5
问给定偶数个数目的数组能否俩俩配对,每对和都是K的倍数。和是K的倍数 (a + b) % K == 0 =>取余后和mod K为0 (a % K + b % K) % K == 0 。统计余数a出现的频率,看K - a的频率是否与之相等。余数为0时满足频率为偶数。
Last updated
Was this helpful?