题解 | #顺时针打印矩阵#
栈的压入、弹出序列
http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
-- coding:utf-8 --
class Solution:
stack=[]
def IsPopOrder(self, pushV, popV):
# write code here
i=0
j=0
while True:
#stack栈顶与popV[j]相等则stack出栈
#若j>len(popV)-1,则应该返回true
if len(self.stack)>0 and self.stack[-1]==popV[j]:
self.stack.pop(-1)
j+=1
elif j>len(popV)-1:
return True
else:
#栈顶与popV[j]不相等则pushV[i]入栈
#若此时i>len(pushV)-1,则应该返回false
if i>len(pushV)-1:
return False
else:
self.stack.append(pushV[i])
i+=1