class Solution:
def countStudents(self , students: List[int], sandwiches: List[int]) -> int:
i = 0 # 栈顶三明治不满足的学生数量
while i < len(students):
if students[0] == sandwiches[0]:
students.pop(0)
sandwiches.pop(0)
i = 0 # 三明治和学生匹配上了,换下一个三明治,数值重置
else:
students.append(students.pop(0))
i += 1 # 未匹配上,则无法拿到三明治的学生数量+1
return len(students)



京公网安备 11010502036488号