diff --git a/problems/0232.用栈实现队列.md b/problems/0232.用栈实现队列.md index b00ffd80..1a56d9f3 100644 --- a/problems/0232.用栈实现队列.md +++ b/problems/0232.用栈实现队列.md @@ -275,15 +275,11 @@ func (this *MyQueue) Pop() int { /** Get the front element. */ func (this *MyQueue) Peek() int { - for len(this.stack) != 0 { - val := this.stack[len(this.stack)-1] - this.stack = this.stack[:len(this.stack)-1] - this.back = append(this.back, val) - } - if len(this.back) == 0 { + val := this.Pop() + if val == 0 { return 0 } - val := this.back[len(this.back)-1] + this.back = append(this.back, val) return val }