leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1700.cpp (527B)


      1 class Solution {
      2   public:
      3     int countStudents(vector<int> &students, vector<int> &sandwiches) {
      4         vector<int> count(2, 0);
      5         queue<int> q;
      6 
      7         for (int s : students) {
      8             q.push(s);
      9             count[s]++;
     10         }
     11 
     12         for (int i = 0; i < sandwiches.size() && count[sandwiches[i]] != 0; q.pop())
     13             if (q.front() == sandwiches[i]) {
     14                 count[sandwiches[i]]--;
     15                 i++;
     16             } else
     17                 q.push(q.front());
     18 
     19         return q.size();
     20     }
     21 };