We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7171203 commit 881119eCopy full SHA for 881119e
scripts/algorithms/I/Implement Stack using Queues/Implement Stack using Queues.go
@@ -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
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