Untitled

 avatar
user_9124840
plain_text
a month ago
565 B
2
Indexable
Never
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;
    }
};
Leave a Comment