1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/购买两块巧克力 [buy-two-chocolates].html
2023-06-02 01:00:40 +08:00

32 lines
1.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组&nbsp;<code>prices</code>&nbsp;,它表示一个商店里若干巧克力的价格。同时给你一个整数&nbsp;<code>money</code>&nbsp;,表示你一开始拥有的钱数。</p>
<p>你必须购买 <strong>恰好&nbsp;</strong>两块巧克力,而且剩余的钱数必须是 <strong>非负数</strong>&nbsp;。同时你想最小化购买两块巧克力的总花费。</p>
<p>请你返回在购买两块巧克力后,最多能剩下多少钱。如果购买任意两块巧克力都超过了你拥有的钱,请你返回 <code>money</code>&nbsp;。注意剩余钱数必须是非负数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>prices = [1,2,2], money = 3
<b>输出:</b>0
<b>解释:</b>分别购买价格为 1 和 2 的巧克力。你剩下 3 - 3 = 0 块钱。所以我们返回 0 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>prices = [3,2,3], money = 3
<b>输出:</b>3
<b>解释:</b>购买任意 2 块巧克力都会超过你拥有的钱数,所以我们返回 3 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= prices.length &lt;= 50</code></li>
<li><code>1 &lt;= prices[i] &lt;= 100</code></li>
<li><code>1 &lt;= money &lt;= 100</code></li>
</ul>