add new solutions
This commit is contained in:
parent
51975f3386
commit
489fa73880
13 changed files with 437 additions and 3 deletions
24
solutions/2/q232/solution.go
Normal file
24
solutions/2/q232/solution.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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();
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue