new file: 0x10/1.cpp
This commit is contained in:
+38
@@ -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();
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user