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

歡迎光臨散文網(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ó)家法律
龙江县| 文安县| 武山县| 吴忠市| 和林格尔县| 惠来县| 休宁县| 巍山| 博湖县| 乐山市| 巴东县| 卢氏县| 扶沟县| 宁化县| 东阳市| 涞水县| 安西县| 清新县| 绍兴县| 涿州市| 西昌市| 连云港市| 迁安市| 蒲江县| 颍上县| 石景山区| 得荣县| 乐都县| 高要市| 拜泉县| 西乌珠穆沁旗| 福清市| 临高县| 宝应县| 太湖县| 尼勒克县| 保康县| 哈巴河县| 丰原市| 宽甸| 洛川县|