题解 | 无法吃午餐的学生数量

无法吃午餐的学生数量

https://www.nowcoder.com/practice/2dac3d7567f741a88ec551caf907934d

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param students int整型vector 
     * @param sandwiches int整型vector 
     * @return int整型
     */
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        queue<int> std,sdw;
        for(int i=0;i<students.size();i++){
            std.push(students[i]);
            sdw.push(sandwiches[i]);
        }
       int c=0;
       while(!sdw.empty()){
        if(sdw.front()==std.front()){ 
            sdw.pop();
            std.pop();
            c=0;
        }
        else {
            int temp=std.front();
            std.pop();
            std.push(temp);
            c++;
            if(c==std.size()){
                break;
            }
        }
       }
       return std.size();
    }
};

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务