TAG
- 芝士水题、思维 − 【类栈】 芝士水题、思维 - 【类栈】 芝士水题、思维−【类栈】时间复杂度
- O ( N ) O(N) O(N)
//
#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int N = 2e5 + 6;
int in[N], maxx[N];
void solve() {
int idx = 0;
int n;
scanf("%d", &n);
while (n--) {
int op;
scanf("%d", &op);
if (op == 0) {
scanf("%d", &in[++idx]);
maxx[idx] = max(maxx[idx-1], in[idx]);
} else if (op == 1) {
if (idx) idx--;
} else if (op == 2) {
printf("%d\n", maxx[idx]);
}
}
}
signed main() {
int t = 1;
// scanf("%d", &t);
while (t--) solve();
return 0;
}
实现细节
- `
参考示意图
-
`
参考链接
- `
作者 | 乐意奥AI