国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

LeetCode 2829. Determine the Minimum Sum of a k-avoiding Array

2023-08-20 12:15 作者:您是打尖兒還是住店呢  | 我要投稿

You are given two integers,?n?and?k.

An array of?distinct?positive integers is called a?k-avoiding?array if there does not exist any pair of distinct elements that sum to?k.

Return?the?minimum?possible sum of a k-avoiding array of length?n.

?

Example 1:

Input: n = 5, k = 4

Output: 18

Explanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18. It can be proven that there is no k-avoiding array with a sum less than 18.

Example 2:

Input: n = 2, k = 6

Output: 3

Explanation: We can construct the array [1,2], which has a sum of 3. It can be proven that there is no k-avoiding array with a sum less than 3.

?

Constraints:

  • 1 <= n, k <= 50

數(shù)字都比較小,直接累加遍歷即可,只是要保留一個(gè)集合,用于判斷是否有差值在集合中即可;

下面是代碼:

Runtime:?7 ms, faster than?100.00%?of?Java?online submissions for?Determine the Minimum Sum of a k-avoiding Array.

Memory Usage:?43.5 MB, less than?100.00%?of?Java?online submissions for?Determine the Minimum Sum of a k-avoiding Array.


LeetCode 2829. Determine the Minimum Sum of a k-avoiding Array的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
永宁县| 金乡县| 新余市| 武平县| 黔江区| 新余市| 中江县| 阳泉市| 嫩江县| 页游| 合水县| 兰西县| 宽城| 景谷| 宜宾县| 东乡| 原阳县| 广宗县| 临汾市| 开江县| 阳江市| 汉源县| 镇雄县| 英超| 黄山市| 文成县| 石门县| 灵台县| 平凉市| 武平县| 阿勒泰市| 平谷区| 秦皇岛市| 吕梁市| 武川县| 射洪县| 梨树县| SHOW| 镇江市| 蒙阴县| 临安市|