Leetcode - 最小栈
程序员文章站
2022-06-17 19:48:10
...
解题思路:(C#)
直接调用Stack相关方法。
public class MinStack {
private Stack<int> myStack;
/** initialize your data structure here. */
public MinStack() {
myStack = new Stack<int>();
}
public void Push(int x) {
myStack.Push(x);
}
public void Pop() {
myStack.Pop();
}
public int Top() {
return myStack.FirstOrDefault();
}
public int GetMin() {
return myStack.Min();
}
}
/**
* 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();
*/
上一篇: 二叉树遍历汇总
下一篇: LeetCode中二叉树相关题