1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
type MinStack struct {
data []int
min []int
top int
}

func min(a int, b int) int {
if(a > b) {
return b
} else {
return a
}
}

/** initialize your data structure here. */
func Constructor() MinStack {
return MinStack {
make([]int, 10010),
make([]int, 10010),
0,
}
}


func (this *MinStack) Push(x int) {
this.top++
if this.top == 1 {
this.data[this.top] = x
this.min[this.top] = x
} else {
this.data[this.top] = x
this.min[this.top] = min(x, this.min[this.top - 1]);
//fmt.Println(this.min[this.top])
}
}


func (this *MinStack) Pop() {
this.top --
}


func (this *MinStack) Top() int {
return this.data[this.top]
}


func (this *MinStack) GetMin() int {
return this.min[this.top]
}


/**
* Your MinStack object will be instantiated and called as such:
* obj := Constructor();
* obj.Push(x);
* obj.Pop();
* param_3 := obj.Top();
* param_4 := obj.GetMin();
*/