欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Leetcode - 最小栈

程序员文章站 2022-06-17 19:48:10
...

Leetcode - 最小栈
解题思路:(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 - 最小栈

相关标签: Leetcode练习