题目
代码
执行用时:364 ms, 在所有 Python3 提交中击败了39.23% 的用户
内存消耗:19 MB, 在所有 Python3 提交中击败了24.23% 的用户
通过测试用例:55 / 55
class CQueue:
def __init__(self):
self.stack1=[]
self.stack2=[]
def appendTail(self, value: int) -> None:
self.stack1.append(value)
def deleteHead(self) -> int:
if not len(self.stack1) and not len(self.stack2):
return -1
else:
if len(self.stack2):
temp=self.stack2[-1]
self.stack2.pop()
return temp
else:
while len(self.stack1):
temp=self.stack1[-1]
self.stack1.pop()
self.stack2.append(temp)
self.stack2.pop()
return temp
# Your CQueue object will be instantiated and called as such:
# obj = CQueue()
# obj.appendTail(value)
# param_2 = obj.deleteHead()