尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

leetcode 耗时100 1700. Number of Students Unable to Eat Lunch

leetcode 耗时100 1700. Number of Students Unable to Eat Lunch Problem: 1700. 无法吃午餐的学生数量双端队列的模拟学生单指针向后移动若连续队首学生和sandwich都不相同的统计数量num std.size()就返回Codeclass Solution { public: int countStudents(vectorint students, vectorint sandwiches) { dequeint stu; int n students.size(); for( int i 0; i n; i ) { stu.push_back(students[i]); } int i 0, num 0; while( i n ) { if(stu.front() sandwiches[i]) { i; stu.pop_front(); num 0; } else { stu.push_back(stu.front()); stu.pop_front(); num; } if(num stu.size()) break; } return stu.size(); } };
返回列表