题解 | 无法吃午餐的学生数量

无法吃午餐的学生数量

https://www.nowcoder.com/practice/2dac3d7567f741a88ec551caf907934d

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param students int整型一维数组 
# @param sandwiches int整型一维数组 
# @return int整型
#
class Solution:
    def countStudents(self , students: List[int], sandwiches: List[int]) -> int:
        # write code here
        for c in sandwiches:#依次遍历所有三明治,当前三明治无论如何都不能被学生拿走时,结束分配
            if c in students:
                students.remove(c)
            else:
                break
        return len(students)#输出没能拿到三明治的学生个数

全部评论

相关推荐

路过的周先森:我就喜欢这种无限复活+筛选快的,比那些投进去就没声还占用投递次数的好多了
投递快手等公司7个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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