滴滴笔试(求第一题实现逻辑)
# -*- coding:utf-8 -*-
class Solution:def IsPopOrder(self, pushV, popV):
# 检验二者长度是否相等
if not pushV or len(pushV)!=len(popV):
return False
stack = []
for i in pushV:
stack.append(i)
while len(stack) and stack[-1] == popV[0]:
stack.pop()
popV.pop(0)
#验证最终栈中所有元素都清空
if len(stack):
return False
return True
#滴滴#