lc-go/solutions/2/q232/solution.go
2026-02-09 10:55:02 +09:00

24 lines
549 B
Go

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();
*/