1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 00:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -9,10 +9,10 @@
"titleSlug": "best-time-to-buy-and-sell-stock-ii",
"content": "<p>You are given an integer array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day.</p>\n\n<p>On each day, you may decide to buy and/or sell the stock. You can only hold <strong>at most one</strong> share of the stock at any time. However, you can buy it then immediately sell it on the <strong>same day</strong>.</p>\n\n<p>Find and return <em>the <strong>maximum</strong> profit you can achieve</em>.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> prices = [7,1,5,3,6,4]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\nThen buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.\nTotal profit is 4 + 3 = 7.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> prices = [1,2,3,4,5]\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\nTotal profit is 4.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> prices = [7,6,4,3,1]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> There is no way to make a positive profit, so we never buy the stock to achieve the maximum profit of 0.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= prices.length &lt;= 3 * 10<sup>4</sup></code></li>\n\t<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"translatedTitle": "买卖股票的最佳时机 II",
"translatedContent": "<p>给一个数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示股票第 <code>i</code> 天的价格。</p>\n\n<p>在每一天,你可能会决定购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以购买,然后在 <strong>同一天</strong> 出售。<br />\n返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> prices = [7,1,5,3,6,4]\n<strong>输出:</strong> 7\n<strong>解释:</strong> 在第 2 天(股票价格 = 1的时候买入在第 3 天(股票价格 = 5的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。\n&nbsp; 随后,在第 4 天(股票价格 = 3的时候买入在第 5 天(股票价格 = 6的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> prices = [1,2,3,4,5]\n<strong>输出:</strong> 4\n<strong>解释:</strong> 在第 1 天(股票价格 = 1的时候买入在第 5 天 (股票价格 = 5的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。\n&nbsp; 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。\n</pre>\n\n<p><strong>示例&nbsp;3:</strong></p>\n\n<pre>\n<strong>输入:</strong> prices = [7,6,4,3,1]\n<strong>输出:</strong> 0\n<strong>解释:</strong> 在这种情况下, 没有交易完成, 所以最大利润为 0。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= prices.length &lt;= 3 * 10<sup>4</sup></code></li>\n\t<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"translatedContent": "<p>给一个整数数组 <code>prices</code> ,其中&nbsp;<code>prices[i]</code> 表示某支股票第 <code>i</code> 天的价格。</p>\n\n<p>在每一天,你可以决定是否购买和/或出售股票。你在任何时候&nbsp;<strong>最多</strong>&nbsp;只能持有 <strong>一股</strong> 股票。你也可以购买,然后在 <strong>同一天</strong> 出售。</p>\n\n<p>返回 <em>你能获得的 <strong>最大</strong> 利润</em>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入</strong>prices = [7,1,5,3,6,4]\n<strong>输出</strong>7\n<strong>解释</strong>在第 2 天(股票价格 = 1的时候买入在第 3 天(股票价格 = 5的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。\n&nbsp; 随后,在第 4 天(股票价格 = 3的时候买入在第 5 天(股票价格 = 6的时候卖出, 这笔交易所能获得利润 = 6 - 3 = 3 。\n 总利润为 4 + 3 = 7 。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入</strong>prices = [1,2,3,4,5]\n<strong>输出</strong>4\n<strong>解释</strong>在第 1 天(股票价格 = 1的时候买入在第 5 天 (股票价格 = 5的时候卖出, 这笔交易所能获得利润 = 5 - 1 = 4 。\n&nbsp; 总利润为 4 。</pre>\n\n<p><strong>示例&nbsp;3</strong></p>\n\n<pre>\n<strong>输入</strong>prices = [7,6,4,3,1]\n<strong>输出</strong>0\n<strong>解释</strong>在这种情况下, 交易无法获得正利润,所以不参与交易可以获得最大利润,最大利润为 0 。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= prices.length &lt;= 3 * 10<sup>4</sup></code></li>\n\t<li><code>0 &lt;= prices[i] &lt;= 10<sup>4</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 1625,
"likes": 1675,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Best Time to Buy and Sell Stock\", \"titleSlug\": \"best-time-to-buy-and-sell-stock\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u4e70\\u5356\\u80a1\\u7968\\u7684\\u6700\\u4f73\\u65f6\\u673a\"}, {\"title\": \"Best Time to Buy and Sell Stock III\", \"titleSlug\": \"best-time-to-buy-and-sell-stock-iii\", \"difficulty\": \"Hard\", \"translatedTitle\": \"\\u4e70\\u5356\\u80a1\\u7968\\u7684\\u6700\\u4f73\\u65f6\\u673a III\"}, {\"title\": \"Best Time to Buy and Sell Stock IV\", \"titleSlug\": \"best-time-to-buy-and-sell-stock-iv\", \"difficulty\": \"Hard\", \"translatedTitle\": \"\\u4e70\\u5356\\u80a1\\u7968\\u7684\\u6700\\u4f73\\u65f6\\u673a IV\"}, {\"title\": \"Best Time to Buy and Sell Stock with Cooldown\", \"titleSlug\": \"best-time-to-buy-and-sell-stock-with-cooldown\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u6700\\u4f73\\u4e70\\u5356\\u80a1\\u7968\\u65f6\\u673a\\u542b\\u51b7\\u51bb\\u671f\"}, {\"title\": \"Best Time to Buy and Sell Stock with Transaction Fee\", \"titleSlug\": \"best-time-to-buy-and-sell-stock-with-transaction-fee\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4e70\\u5356\\u80a1\\u7968\\u7684\\u6700\\u4f73\\u65f6\\u673a\\u542b\\u624b\\u7eed\\u8d39\"}]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"591.8K\", \"totalSubmission\": \"846.3K\", \"totalAcceptedRaw\": 591800, \"totalSubmissionRaw\": 846274, \"acRate\": \"69.9%\"}",
"stats": "{\"totalAccepted\": \"618.3K\", \"totalSubmission\": \"881K\", \"totalAcceptedRaw\": 618296, \"totalSubmissionRaw\": 880997, \"acRate\": \"70.2%\"}",
"hints": [],
"solution": {
"id": "90",