leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1700.cpp (527B)
0 class Solution { 1 public: 2 int countStudents(vector<int> &students, vector<int> &sandwiches) { 3 vector<int> count(2, 0); 4 queue<int> q; 5 6 for (int s : students) { 7 q.push(s); 8 count[s]++; 9 } 10 11 for (int i = 0; i < sandwiches.size() && count[sandwiches[i]] != 0; q.pop()) 12 if (q.front() == sandwiches[i]) { 13 count[sandwiches[i]]--; 14 i++; 15 } else 16 q.push(q.front()); 17 18 return q.size(); 19 } 20 };