// 1700. Number of Students Unable to Eat Lunch
class Solution {
public int countStudents(int[] students, int[] sandwiches) {
int circleStudents = 0;
int squareStudents = 0;
for (int student : students) {
if (student == 0) ++circleStudents;
else ++squareStudents;
}
for (int sandwich : sandwiches) {
if (sandwich == 0) {
if (circleStudents > 0) --circleStudents;
else return squareStudents;
} else {
if (squareStudents > 0) --squareStudents;
else return circleStudents;
}
}
return 0;
}
}
学习笔记:
这是一道简单题,虽说看上去说是队列和栈,实际上根本都用不到。
就只需要统计一下学生,反正学生不喜欢会继续排的。
一直到栈顶的三文治没人拿为止,那剩下的那一类学生都要挨饿。