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

无法吃午餐的学生数量

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
        num = 0
        while len(students) != 0:
            if students[0] == sandwiches[0]:
                students.pop(0)
                sandwiches.pop(0)
                num = 0
            else:
                students.append(students.pop(0))
                num += 1
                if num > len(students):
                    return len(students)
        return 0

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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