new file: 0x10/1.cpp

This commit is contained in:
hanyixuanten
2026-08-24 19:24:58 +08:00
parent f025899392
commit 124a3e999e
+38
View File
@@ -0,0 +1,38 @@
// 41
class MinStack
{
public:
/** initialize your data structure here. */
int a[105], tot = 0;
MinStack()
{
}
void push(int x)
{
a[++tot] = x;
}
void pop()
{
tot--;
}
int top()
{
return a[tot];
}
int getMin()
{
int ans = 1e9;
for (int i = tot; i >= 1; i--)
ans = (a[i] < ans) ? a[i] : ans;
return ans;
}
};
/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(x);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/