Byte by Byte

1700. Number of Students Unable to Eat Lunch.cpp 본문

개발 로그/알고리즘

1700. Number of Students Unable to Eat Lunch.cpp

CyberSoak 2021. 11. 21. 12:06

🔑 루프 기본 연습

class Solution {
public:
    int countStudents(vector<int>& students, vector<int>& sandwiches) {
        
        int cnt = 0;
        while(1){
            if(sandwiches[0] ==students[0]){
                sandwiches.erase(sandwiches.begin());
                students.erase(students.begin());
                cnt = 0;
            }
            else{
                students.push_back(students[0]);
                students.erase(students.begin());
                cnt++;
            }
            if(cnt == students.size()) break;
            
        }
        return students.size();
    }
};

 

'개발 로그 > 알고리즘' 카테고리의 다른 글

202. Happy Number.cpp  (0) 2021.11.24
766. Toeplitz Matrix.cpp  (0) 2021.11.22
349. Intersection of Two Arrays.cpp  (0) 2021.11.20
1636. Sort Array by Increasing Frequency.cpp  (0) 2021.11.20
1002. Find Common Characters.cpp  (0) 2021.11.19