LeetCode #1700

Number of Students Unable to Eat Lunch

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        int N = (int)students.size();
        vector<int> used(N);
        int ret = 0, i = 0;
        for(int x: sandwiches) {
            bool flag = false;
            for(int k = 0; k < N; ++k, i = (i + 1) % N) {
                if(used[i]) continue;
                if(students[i] == x) {
                    flag = true;
                    break;
                }
            }
            if(!flag) break;
            ++ ret;
            used[i] = true;
        }
        return N - ret;
    }
};

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.