Skip to content

Commit 881119e

Browse files
committed
Runtime: 1 ms (Top 81.11%) | Memory: 2.10 MB (Top 22.78%)
1 parent 7171203 commit 881119e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Runtime: 1 ms (Top 81.11%) | Memory: 2.10 MB (Top 22.78%)
2+
3+
type MyStack struct {
4+
q []int
5+
}
6+
7+
func Constructor() MyStack {
8+
return MyStack{}
9+
}
10+
11+
func (this *MyStack) Push(x int) {
12+
this.q = append(this.q, x)
13+
for i := 0; i < len(this.q)-1; i++ {
14+
this.q = append(this.q, this.q[0])
15+
this.q = this.q[1:]
16+
}
17+
}
18+
19+
func (this *MyStack) Pop() int {
20+
val := this.q[0]
21+
this.q = this.q[1:]
22+
return val
23+
}
24+
25+
func (this *MyStack) Top() int {
26+
return this.q[0]
27+
}
28+
29+
func (this *MyStack) Empty() bool {
30+
return len(this.q) == 0
31+
}

0 commit comments

Comments
 (0)