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

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

LeetCode 2706. Buy Two Chocolates

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

You are given an integer array?prices?representing the prices of various chocolates in a store. You are also given a single integer?money, which represents your initial amount of money.

You must buy?exactly?two chocolates in such a way that you still have some?non-negative?leftover money. You would like to minimize the sum of the prices of the two chocolates you buy.

Return?the amount of money you will have leftover after buying the two chocolates. If there is no way for you to buy two chocolates without ending up in debt, return?money. Note that the leftover must be non-negative.

?

Example 1:

Input: prices = [1,2,2], money = 3

Output: 0

Explanation: Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0.

Example 2:

Input: prices = [3,2,3], money = 3

Output: 3

Explanation: You cannot buy 2 chocolates without going in debt, so we return 3.

?

Constraints:

  • 2 <= prices.length <= 50

  • 1 <= prices[i] <= 100

  • 1 <= money <= 100

排序一下判斷一下即可,下面是代碼:


3 ms, faster than?33.33%?of?Java?online submissions for?Buy Two Chocolates.

Memory Usage:?43.6 MB, less than?33.33%?of?Java?online submissions for?Buy Two Chocolates.


LeetCode 2706. Buy Two Chocolates的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
田东县| 双牌县| 静宁县| 西乌珠穆沁旗| 东明县| 香河县| 永安市| 应城市| 阿瓦提县| 湟中县| 出国| 吉木萨尔县| 特克斯县| 阜康市| 抚松县| 虹口区| 青州市| 长垣县| 崇义县| 和龙市| 锡林浩特市| 蒙自县| 忻州市| 都安| 图片| 峨山| 绥棱县| 灌云县| 金阳县| 肇庆市| 卢龙县| 高清| 辉南县| 志丹县| 伊川县| 新蔡县| 天门市| 陆河县| 仁怀市| 定州市| 台北市|