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

歡迎光臨散文網(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)遵守國家法律
北宁市| 和顺县| 乌兰察布市| 武威市| 宁陕县| 尼玛县| 久治县| 丰原市| 靖安县| 阿克陶县| 滨海县| 德钦县| 普兰店市| 睢宁县| 施甸县| 绵阳市| 兴和县| 托克托县| 大城县| 临潭县| 永安市| 北票市| 乐至县| 都兰县| 固安县| 巨鹿县| 和硕县| 旬邑县| 通州市| 陇西县| 新疆| 东城区| 玛曲县| 盐亭县| 左权县| 萨嘎县| 富民县| 孟村| 房山区| 锦州市| 新河县|