1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 23: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

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一支股票价格的数据流。数据流中每一条记录包含一个 <strong>时间戳</strong>&nbsp;和该时间点股票对应的 <strong>价格</strong>&nbsp;。</p>\n\n<p>不巧的是,由于股票市场内在的波动性,股票价格记录可能不是按时间顺序到来的。某些情况下,有的记录可能是错的。如果两个有相同时间戳的记录出现在数据流中,前一条记录视为错误记录,后出现的记录 <b>更正</b>&nbsp;前一条错误的记录。</p>\n\n<p>请你设计一个算法,实现:</p>\n\n<ul>\n\t<li><strong>更新 </strong>股票在某一时间戳的股票价格,如果有之前同一时间戳的价格,这一操作将&nbsp;<strong>更正</strong>&nbsp;之前的错误价格。</li>\n\t<li>找到当前记录里 <b>最新股票价格</b>&nbsp;。<strong>最新股票价格</strong>&nbsp;定义为时间戳最晚的股票价格。</li>\n\t<li>找到当前记录里股票的 <strong>最高价格</strong>&nbsp;。</li>\n\t<li>找到当前记录里股票的 <strong>最低价格</strong>&nbsp;。</li>\n</ul>\n\n<p>请你实现&nbsp;<code>StockPrice</code>&nbsp;类:</p>\n\n<ul>\n\t<li><code>StockPrice()</code>&nbsp;初始化对象,当前无股票价格记录。</li>\n\t<li><code>void update(int timestamp, int price)</code>&nbsp;在时间点 <code>timestamp</code>&nbsp;更新股票价格为 <code>price</code>&nbsp;。</li>\n\t<li><code>int current()</code>&nbsp;返回股票 <strong>最新价格</strong>&nbsp;。</li>\n\t<li><code>int maximum()</code>&nbsp;返回股票 <strong>最高价格</strong>&nbsp;。</li>\n\t<li><code>int minimum()</code>&nbsp;返回股票 <strong>最低价格</strong>&nbsp;。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>\n[\"StockPrice\", \"update\", \"update\", \"current\", \"maximum\", \"update\", \"maximum\", \"update\", \"minimum\"]\n[[], [1, 10], [2, 5], [], [], [1, 3], [], [4, 2], []]\n<strong>输出:</strong>\n[null, null, null, 5, 10, null, 5, null, 2]\n\n<strong>解释:</strong>\nStockPrice stockPrice = new StockPrice();\nstockPrice.update(1, 10); // 时间戳为 [1] ,对应的股票价格为 [10] 。\nstockPrice.update(2, 5); // 时间戳为 [1,2] ,对应的股票价格为 [10,5] 。\nstockPrice.current(); // 返回 5 ,最新时间戳为 2 ,对应价格为 5 。\nstockPrice.maximum(); // 返回 10 ,最高价格的时间戳为 1 ,价格为 10 。\nstockPrice.update(1, 3); // 之前时间戳为 1 的价格错误,价格更新为 3 。\n // 时间戳为 [1,2] ,对应股票价格为 [3,5] 。\nstockPrice.maximum(); // 返回 5 ,更正后最高价格为 5 。\nstockPrice.update(4, 2); // 时间戳为 [1,2,4] ,对应价格为 [3,5,2] 。\nstockPrice.minimum(); // 返回 2 ,最低价格时间戳为 4 ,价格为 2 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= timestamp, price &lt;= 10<sup>9</sup></code></li>\n\t<li><code>update</code><code>current</code><code>maximum</code>&nbsp;和&nbsp;<code>minimum</code>&nbsp;<strong>总</strong> 调用次数不超过&nbsp;<code>10<sup>5</sup></code>&nbsp;。</li>\n\t<li><code>current</code><code>maximum</code>&nbsp;和&nbsp;<code>minimum</code>&nbsp;被调用时,<code>update</code>&nbsp;操作 <strong>至少</strong>&nbsp;已经被调用过 <strong>一次</strong>&nbsp;。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 109,
"likes": 111,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"20.7K\", \"totalSubmission\": \"43.8K\", \"totalAcceptedRaw\": 20665, \"totalSubmissionRaw\": 43835, \"acRate\": \"47.1%\"}",
"stats": "{\"totalAccepted\": \"20.9K\", \"totalSubmission\": \"44.6K\", \"totalAcceptedRaw\": 20920, \"totalSubmissionRaw\": 44600, \"acRate\": \"46.9%\"}",
"hints": [
"How would you solve the problem for offline queries (all queries given at once)?",
"Think about which data structure can help insert and delete the most optimal way."