主要要注意的是python中的类变量 self.a
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.a = []
self.b = []
def push(self, node):
# write code here
self.a.append(node)
def pop(self):
# return xx
if self.b:
return self.b.pop()
else:
while (self.a):
self.b.append(self.a.pop())
return self.b.pop()