劍指offer——05用兩個棧實現隊列(Python3)

思路:(轉)node

代碼:app

# -*- coding:utf-8 -*-
class Solution:
stack1 = []
stack2 = []blog

def push(self, node):
self.stack1.append(node)utf-8

def pop(self):
if len(self.stack2) > 0:
return self.stack2.pop()
else:
while len(self.stack1) > 0:
self.stack2.append(self.stack1.pop())
return self.pop()io

相關文章
相關標籤/搜索