去掉len(s)==0这个条件,直接把辅助栈底弄为-1,嘿嘿
class Solution:
def IsPopOrder(self , pushV: List[int], popV: List[int]) -> bool:
n = len(pushV)
s= [-1]
j=0
for i in range(n):
while j<n and ( s[-1] != popV[i]):
s.append(pushV[j])
j+=1
if s[-1] == popV[i]:
s.pop()
else :
return False
return True