当前位置:网站首页>Leetcode1497- check whether array pairs can be divided by K - array - hash table - count
Leetcode1497- check whether array pairs can be divided by K - array - hash table - count
2022-07-01 04:53:00 【Li Fan, hurry up】
Note:
1、 All the numbers in the array , All the k Perform a remainder operation , In this way, the question can be changed into whether the sum of two numbers is equal to k
2、 Just take the remainder and open an array to record , After each number is fetched, the corresponding number is
3、 Traverse half the array , Each judgment mod[i] == mod[k - i] that will do
4、 Last , Because it's possible that two people can get the remainder 0 The situation of , Judge 0 Position number is not 2 Multiple
The code is as follows :
class Solution {
public:
bool canArrange(vector<int>& arr, int k) {
vector<int> mod(k);
for(auto num: arr)
mod[(num % k + k) % k] ++;
for(int i = 1; i <= k / 2; i ++)
if(mod[i] != mod[k - i])
return false;
return mod[0] % 2 == 0;
}
};
边栏推荐
猜你喜欢

Pytorch(四) —— 可视化工具 Visdom

C - detailed explanation of operators and summary of use cases

【暑期每日一题】洛谷 P5886 Hello, 2020!
![[hard ten treasures] - 1 [basic knowledge] classification of power supply](/img/a8/f129c9d15ca6ed99db1dacfc750ead.png)
[hard ten treasures] - 1 [basic knowledge] classification of power supply

STM32 光敏电阻传感器&两路AD采集

常用的Transforms中的方法

Pytoch (III) -- function optimization

分布式锁的实现

Use of STM32 expansion board temperature sensor and temperature humidity sensor

How to do the performance pressure test of "Health Code"
随机推荐
One click shell to automatically deploy any version of redis
LeetCode_ 53 (maximum subarray and)
STM32扩展板 数码管显示
Construction of Meizhou nursing laboratory: equipment configuration
神经网络-最大池化的使用
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Kodori tree board
打印流与System.setout();
How to use common datasets in pytorch
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
FileInputStream
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
Detailed explanation of distributed global unique ID solution
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
Design experience of Meizhou clinical laboratory
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Basic exercise of test questions hexadecimal to decimal
分布式架构系统拆分原则、需求、微服务拆分步骤
Principle, technology and implementation scheme of data consistency in distributed database
[daily question in summer] letter delivery by p1629 postman in Luogu (to be continued...)
