| 题目名称 | 2857. Push,Pop,GetMin |
|---|---|
| 输入输出 | minstack.in/out |
| 难度等级 | ★☆ |
| 时间限制 | 1000 ms (1 s) |
| 内存限制 | 512 MiB |
| 测试数据 | 5 |
| 题目来源 |
|
| 开放分组 | 全部用户 |
| 提交状态 | |
| 分类标签 | |
| 分享题解 |
| 通过:1, 提交:1, 通过率:100% | ||||
|
|
100 | 0.013 s | 3.90 MiB | C++ |
| 关于 Push,Pop,GetMin 的近10条评论(全部评论) |
|---|
设计一个支持push,pop,top等操作并且可以在O$(1)$时间内检索出最小元素的栈。
push(x) // 将元素x插入栈中 pop() // 移除栈顶元素 top() // 得到栈顶元素 getMin() // 得到栈中最小元素
你需要实现如下函数,可以使用STL stack。
#include "test.h"
void push(int x)
{
}
void pop()
{
}
int top()
{
}
int getMin()
{
}
push(-1); push(3); push(-4); getMin(); // 函数返回-4 pop(); top(); // 函数返回3 getMin(); // 函数返回1
评测时必须使用文件输入输出评测机。