五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

LeetCode 2517. Maximum Tastiness of Candy Basket

2023-06-01 08:26 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an array of positive integers?price?where?price[i]?denotes the price of the?ith?candy and a positive integer?k.

The store sells baskets of?k?distinct?candies. The?tastiness?of a candy basket is the smallest absolute difference of the?prices?of any two candies in the basket.

Return?the?maximum?tastiness of a candy basket.

?

Example 1:

Input: price = [13,5,1,8,21,2], k = 3

Output: 8

Explanation:?

Choose the candies with the prices [13,5,21].?

The tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.?

It can be proven that 8 is the maximum tastiness that can be achieved.

Example 2:

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

Output: 2

Explanation: Choose the candies with the prices [1,3].?

The tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.?

It can be proven that 2 is the maximum tastiness that can be achieved.

Example 3:

Input: price = [7,7,7,7], k = 2

Output: 0

Explanation: Choosing any two distinct candies from the candies we have will result in a tastiness of 0.

?

Constraints:

  • 2 <= k <= price.length <= 105

  • 1 <= price[i] <= 109

一般遇到最大的值,最小值,都是二分,只是怎么二分需要仔細(xì)考慮的,

這個就是差值最大,最小值之間做二分,

下面是代碼:

Runtime:?41 ms, faster than?99.07%?of?Java?online submissions for?Maximum Tastiness of Candy Basket.

Memory Usage:?56.3 MB, less than?13.55%?of?Java?online submissions for?Maximum Tastiness of Candy Basket.


LeetCode 2517. Maximum Tastiness of Candy Basket的評論 (共 條)

分享到微博請遵守國家法律
荆州市| 忻州市| 民县| 波密县| 金平| 五原县| 普兰店市| 侯马市| 车致| 桦甸市| 慈溪市| 呼图壁县| 江北区| 绥滨县| 谢通门县| 南涧| 新干县| 昌都县| 巴彦县| 西平县| 彩票| 宁强县| 桂东县| 尼勒克县| 阿瓦提县| 玉屏| 顺平县| 万年县| 巴东县| 资兴市| 县级市| 兴海县| 山阳县| 方正县| 杭锦后旗| 都兰县| 胶州市| 静安区| 长葛市| 高阳县| 武城县|