题解 | 机器翻译

机器翻译

https://www.nowcoder.com/practice/45ecfecd83104f37a685016361be504c

m, n = map(int,input().split())
w = list(map(int,input().split()))
sm, ans = [], 0#栈,未命中次数
for c in w:
    if c not in sm:#未命中
        ans += 1
        if len(sm)>=m:#栈满了,首元素出栈
            sm.pop(0)
        sm.append(c)#未命中新元素入栈尾
print(ans)

全部评论

相关推荐

在考古的丘比特很冷艳:[牛泪我横向一周多自动挂了,面试答的还行,感觉挂的莫名其妙
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务