25 lines
651 B
Go
25 lines
651 B
Go
// Package q232 implements a solution for https://leetcode.com/problems/implement-queue-using-stacks/
|
|
package q232
|
|
|
|
type MyQueue struct{ data []int }
|
|
|
|
func Constructor() MyQueue { return MyQueue{} }
|
|
func (q *MyQueue) Push(x int) { q.data = append(q.data, x) }
|
|
|
|
func (q *MyQueue) Pop() int {
|
|
ret := q.data[0]
|
|
q.data = q.data[1:]
|
|
return ret
|
|
}
|
|
|
|
func (q *MyQueue) Peek() int { return q.data[0] }
|
|
func (q *MyQueue) Empty() bool { return len(q.data) == 0 }
|
|
|
|
/**
|
|
* Your MyQueue object will be instantiated and called as such:
|
|
* obj := Constructor();
|
|
* obj.Push(x);
|
|
* param_2 := obj.Pop();
|
|
* param_3 := obj.Peek();
|
|
* param_4 := obj.Empty();
|
|
*/
|