剑指offer-栈的压入、弹出序列

来源:互联网 发布:百度软件开发 编辑:程序博客网 时间:2024/06/01 10:36
class Solution:    def IsPopOrder(self, pushV, popV):        # write code here        l,j=[],0        if not pushV or not popV:            return False        for i in range(len(pushV)):            l.append(pushV[i])            while j<len(popV) and popV[j]==l[-1]:                l.pop()                j+=1        return not l

参考https://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106的思路来写的。

原创粉丝点击