mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 11:08:15 +08:00
1 line
485 B
HTML
1 line
485 B
HTML
<p>请设计一个栈,除了常规栈支持的pop与push函数以外,还支持min函数,该函数返回栈元素中的最小值。执行push、pop和min操作的时间复杂度必须为O(1)。</p><br><p><strong>示例:</strong><pre>MinStack minStack = new MinStack();<br>minStack.push(-2);<br>minStack.push(0);<br>minStack.push(-3);<br>minStack.getMin(); --> 返回 -3.<br>minStack.pop();<br>minStack.top(); --> 返回 0.<br>minStack.getMin(); --> 返回 -2.</pre></p> |