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)/设计自助结算系统 [dui-lie-de-zui-da-zhi-lcof].html
2023-12-09 18:53:53 +08:00

43 lines
1.1 KiB
HTML
Raw 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>请设计一个自助结账系统,该系统需要通过一个队列来模拟顾客通过购物车的结算过程,需要实现的功能有:</p>
<ul>
<li><code>get_max()</code>:获取结算商品中的最高价格,如果队列为空,则返回 -1</li>
<li><code>add(value)</code>:将价格为 <code>value</code> 的商品加入待结算商品队列的尾部</li>
<li><code>remove()</code>:移除第一个待结算的商品价格,如果队列为空,则返回 -1</li>
</ul>
<p>注意,为保证该系统运转高效性,以上函数的均摊时间复杂度均为 O(1)</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
输入:
["Checkout","add","add","get_max","remove","get_max"]
[[],[4],[7],[],[],[]]
输出: [null,null,null,7,4,7]
</pre>
<p><strong>示例 2</strong></p>
<pre>
输入:
["Checkout","remove","get_max"]
[[],[],[]]
输出: [null,-1,-1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= get_max, add, remove 的总操作数&nbsp;&lt;= 10000</code></li>
<li><code>1 &lt;= value &lt;= 10^5</code></li>
</ul>
<p>&nbsp;</p>