题目描述
blablabla
样例
blablabla
算法1
() $O(n^2)$
blablabla
时间复杂度分析:blablabla
Python 代码
class MyQueue(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.stack1 = []
self.stack2 = []
def push(self, x):
"""
Push element x to the back of queue.
:type x: int
:rtype: void
"""
self.stack1.append(x)
def adjust(self):
if len(self.stack2) == 0:
while len(self.stack1) != 0:
self.stack2.append(self.stack1.pop())
def pop(self):
"""
Removes the element from in front of queue and returns that element.
:rtype: int
"""
self.adjust()
return self.stack2.pop()
def peek(self):
"""
Get the front element.
:rtype: int
"""
self.adjust()
return self.stack2[len(self.stack2) - 1]
def empty(self):
"""
Returns whether the queue is empty.
:rtype: bool
"""
return len(self.stack1) == 0 and len(self.stack2) == 0
# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
请问这个
self.stack2[len(self.stack2) - 1]
对应栈的什么操作