Untitled
user_9124840
plain_text
a year ago
565 B
16
Indexable
class Solution {
public:
int countStudents(vector<int>& students, vector<int>& sandwiches) {
int numNeed1 = 0, numNeed0 = 0;
for(int a : students) {
if(a == 1) numNeed1++;
else numNeed0++;
}
for(int s : sandwiches) {
if(s == 0 && numNeed0 > 0) {
numNeed0--;
} else if(s == 1 && numNeed1 > 0) {
numNeed1--;
} else {
break;
}
}
return numNeed0 + numNeed1;
}
};
Editor is loading...
Leave a Comment