/
676767ap
/
data_structures_examples
Обзор
Документация
Войти
/
676767ap
/
data_structures_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
stack/stack.go
30 строк
573 B
Anton Polikarpov
minStack
28 июн 2024, 14:37
28 июн 2024, 14:37
2ec4524
Код
Авторство
О чём код?
package stack import "math" type MinStack struct { stk1 []int stk2 []int } func Constructor() MinStack { return MinStack{[]int{}, []int{math.MaxInt32}} } func (this *MinStack) Push(val int) { this.stk1 = append(this.stk1, val) this.stk2 = append(this.stk2, min(val, this.stk2[len(this.stk2)-1])) } func (this *MinStack) Pop() { this.stk1 = this.stk1[:len(this.stk1)-1] this.stk2 = this.stk2[:len(this.stk2)-1] } func (this *MinStack) Top() int { return this.stk1[len(this.stk1)-1] } func (this *MinStack) GetMin() int { return this.stk2[len(this.stk2)-1] }