最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 1497. Check If Array Pairs Are Divisible by k

2023-05-04 15:03 作者:您是打尖兒還是住店呢  | 我要投稿

iven 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:

Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5

Output: true

Explanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).

Example 2:

Input: arr = [1,2,3,4,5,6], k = 7

Output: true

Explanation: Pairs are (1,6),(2,5) and(3,4).

Example 3:

Input: arr = [1,2,3,4,5,6], k = 10

Output: false

Explanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.

?

Constraints:

  • arr.length == n

  • 1 <= n <= 105

  • n?is even.

  • -109?<= arr[i] <= 109

  • 1 <= k <= 105

我用hashmap總不過,真的想不出來是什么原因,因?yàn)槭窃跀?shù)據(jù)集很大的時(shí)候不過的,

沒辦法就換成數(shù)組了,秒過。。。。

Runtime:?5 ms, faster than?96.99%?of?Java?online submissions for?Check If Array Pairs Are Divisible by k.

Memory Usage:?50.3 MB, less than?85.24%?of?Java?online submissions for?Check If Array Pairs Are Divisible by k.


LeetCode 1497. Check If Array Pairs Are Divisible by k的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
建昌县| 辽阳市| 沁水县| 汕尾市| 龙南县| 林芝县| 阜南县| 宁海县| 昌图县| 谢通门县| 峨眉山市| 马关县| 胶州市| 大冶市| 合作市| 武义县| 长岛县| 湘阴县| 宜兴市| 红原县| 墨竹工卡县| 同江市| 德惠市| 榆树市| 平定县| 池州市| 扎兰屯市| 元谋县| 旺苍县| 永善县| 枝江市| 万年县| 汕尾市| 准格尔旗| 迁西县| 县级市| 宣汉县| 通渭县| 北海市| 蒙山县| 蕲春县|