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)/买卖股票的最佳时机含手续费 [best-time-to-buy-and-sell-stock-with-transaction-fee].html
2022-03-29 12:43:11 +08:00

39 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>,其中 <code>prices[i]</code>表示第&nbsp;<code>i</code>&nbsp;天的股票价格 ;整数&nbsp;<code>fee</code> 代表了交易股票的手续费用。</p>
<p>你可以无限次地完成交易,但是你每笔交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。</p>
<p>返回获得利润的最大值。</p>
<p><strong>注意:</strong>这里的一笔交易指买入持有并卖出股票的整个过程,每笔交易你只需要为支付一次手续费。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>prices = [1, 3, 2, 8, 4, 9], fee = 2
<strong>输出:</strong>8
<strong>解释:</strong>能够达到的最大利润:
在此处买入&nbsp;prices[0] = 1
在此处卖出 prices[3] = 8
在此处买入 prices[4] = 4
在此处卖出 prices[5] = 9
总利润:&nbsp;((8 - 1) - 2) + ((9 - 4) - 2) = 8</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>prices = [1,3,7,5,10,3], fee = 3
<strong>输出:</strong>6
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= prices.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= prices[i] &lt; 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= fee &lt; 5 * 10<sup>4</sup></code></li>
</ul>