// An highlighted block
type MinStack struct {
stack *list.List
}
/** initialize your data structure here. */
func Constructor() MinStack {
return MinStack{stack:list.New(),}
}
func (this *MinStack) Push(x int) {
if this.stack.Len()!=0{
temp:=this.stack.Back().Value.(int)
this.stack.PushBack(x)
if temp<x{
this.stack.PushBack(temp)
}else {
this.stack.PushBack(x)
}
}else {
this.stack.PushBack(x)
this.stack.PushBack(x)
}
}
func (this *MinStack) Pop() {
this.stack.Remove(this.stack.Back())
this.stack.Remove(this.stack.Back())
}
func (this *MinStack) Top() int {
return this.stack.Back().Prev().Value.(int)
}
func (this *MinStack) GetMin() int {
return this.stack.Back().Value.(int)
}
第五周,作业2
最新推荐文章于 2024-05-13 10:25:29 发布