全球视讯!LeetCode 2176. Count Equal and Divisible Pairs in an Array
哔哩哔哩 2023-04-11 10:02:33

Given a 0-indexed integer array numsof length nand an integer k, return the number of pairs (i, j)where 0 <= i < j < n, such that nums[i] == nums[j]and (i * j)is divisible by k.

Example 1:


(资料图片仅供参考)

Input: nums = [3,1,2,2,2,1,3], k = 2

Output: 4

Explanation:

There are 4 pairs that meet all the requirements: 

- nums[0] == nums[6], and 0 * 6 == 0, which is divisible by 2. 

- nums[2] == nums[3], and 2 * 3 == 6, which is divisible by 2. 

- nums[2] == nums[4], and 2 * 4 == 8, which is divisible by 2. 

- nums[3] == nums[4], and 3 * 4 == 12, which is divisible by 2.

Example 2:

Input: nums = [1,2,3,4], k = 1

Output: 0

Explanation: Since no value in nums is repeated, there are no pairs (i,j) that meet all the requirements.

Constraints:

1 <= nums.length <= 100

1 <= nums[i], k <= 100

Easy 题目,遍历即可。

Runtime: 3 ms, faster than 99.48% of Java online submissions for Count Equal and Divisible Pairs in an Array.

Memory Usage: 42.4 MB, less than 31.63% of Java online submissions for Count Equal and Divisible Pairs in an Array.

猜你喜欢

全球视讯!LeetCode 2176. Count Equal and Divisible Pairs in an Array

2023-04-11

环球热议:让媒体传播赋能城市更新

2023-04-11

“乾动2号”深远海养殖平台投放下水 一年可养殖大黄鱼约200吨

2023-04-11

文化和旅游部办公厅发文进一步整治“不合理低价游”

2023-04-11

当前热门:「网言」自媒体造谣乱象,要“治”

2023-04-11

环球微头条丨会同农商银行全力支持高标准农田建设

2023-04-10

矮生百慕大草怎么种植(矮生百慕大草耐修剪、耐践踏、适应性强)-每日时讯

2023-04-10

记者手记:薪火相传——中国援苏丹医疗队尼罗河畔半个世纪的驻守_全球今热点

2023-04-10

索罗门自行车官网_索罗门自行车

2023-04-10

沂水城投集团8亿元私募债更新至“已反馈”

2023-04-10

发售两年之后 卡普空终于移除了《生化危机8》D加密

2023-04-10

天天速看:陇东新区石油勘探斩获百吨油流井

2023-04-10

最新快讯!2023年象山随迁子女转校需要量化积分吗?

2023-04-10

附加赛赔率:湖人鹈鹕热火和猛龙被看好取胜

2023-04-10

贾康:2023年经济展望与创新推动产业升级

2023-04-10

热门推荐