Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countStudents(vector<int>& students, vector<int>& sandwiches) {
- // queue<int> stu;
- stack<int> san;
- // for(int i:students){
- // stu.push(i);
- // }
- for(int i:sandwiches){
- san.push(i);
- }
- int changes=1;
- while(changes==1){
- changes=0;
- for(int i=0;i<students.size();i++){
- if(san.size()==0){
- break;
- }
- if(san.top()==students[i]){
- cout<<san.top()<<' '<<students[i]<<endl;
- students[i]=-1;
- changes=1;
- san.pop();
- }
- }
- }
- int ans=0;
- for(int i:students){
- // cout<<i<<' ';
- if(i!=-1){
- ans++;
- }
- }
- cout<<endl;
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement