题解 | #栈的压入、弹出序列#

栈的压入、弹出序列

https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106

栈顶弹出后,切片,判断首项是否为新的栈顶

from re import T
class Solution:
    def IsPopOrder(self , pushV: List[int], popV: List[int]) -> bool:
        # write code here
        if sorted(popV)!=sorted(pushV):
            return False                                  
        while popV:
            v1=popV.index(pushV[-1])                       
            popV.pop(v1)
            if len(popV)<v1+1:
                return True                       
            cut=popV[v1:]
            cut=[pushV.index(i) for i in cut]
            if cut[0]==max(cut):               
                pushV.pop(-1)
                continue
            else:
                return False

全部评论

相关推荐

CADILLAC_:我要用bava 不要用java 了 啊啊啊啊啊啊啊啊啊啊啊
点赞 评论 收藏
分享
在看数据的傻狍子很忙碌:学生思维好重,而心很急,自己想想真的能直接做有难度的东西吗?任何错误都是需要人担责的,你实习生可以跑路,你的同事领导呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务