当前位置:网站首页>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;
}
};
边栏推荐
- [daily question in summer] function of rogu p3742 UMI
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Leecode question brushing record 1332 delete palindrome subsequence
- Oracle views the creation time of the tablespace in the database
- Pytoch (I) -- basic grammar
- [hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
- Some tools that research dogs may need
- JS to solve the problem of floating point multiplication precision loss
- Neural network convolution layer
- LeetCode_53(最大子数组和)
猜你喜欢

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

Dataloader的使用

C - detailed explanation of operators and summary of use cases

Technology sharing | broadcast function design in integrated dispatching

STM32扩展版 按键扫描

Pytorch(三) —— 函数优化

常用的Transforms中的方法

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点
![[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply](/img/c2/6dfb9f477306edb46ff2a6a6ca32dd.png)
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply

RuntimeError: “max_pool2d“ not implemented for ‘Long‘
随机推荐
Data loading and preprocessing
Pytoch (I) -- basic grammar
1076 Forwards on Weibo
手动实现一个简单的栈
【FTP】FTP常用命令,持续更新中……
Shell analysis server log command collection
Codeworks round 449 (Div. 1) C. Kodori tree template
js解决浮点数相乘精度丢失问题
神经网络的基本骨架-nn.Moudle的使用
Basic skeleton of neural network nn Use of moudle
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Manually implement a simple stack
Difference between cookie and session
打印流与System.setout();
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
Several methods of creating thread classes
分布式锁的实现
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Quelques outils dont les chiens scientifiques pourraient avoir besoin
VIM easy to use tutorial