美文网首页
31 栈的压入,弹出

31 栈的压入,弹出

作者: 土味老猪 | 来源:发表于2018-06-13 11:04 被阅读0次
class Solution():
    def stacktest(self,stackin,stackout):
        stackOrg = []
        stackOrg += stackin[:stackin.index(stackout[0])+1]
        stackin = stackin[stackin.index(stackout[0])+1:]
        for i in stackout:
            if stackOrg and i == stackOrg[-1]:
                stackOrg.pop()

            else:
                if i not in stackin:
                    return False
                stackOrg += stackin[:stackin.index(i)]

        return True




#test
s = Solution()

print(s.stacktest([1,2,3,4,5],[1,2,3,4,5]))

相关文章

网友评论

      本文标题:31 栈的压入,弹出

      本文链接:https://www.haomeiwen.com/subject/hdqjeftx.html