[551. Student Attendance Record I] C++ AC


  • 0
    class Solution {
    public:
    bool checkRecord(string s) {
        int late = 0;
        int abse = 0;
        for(int i = 0; i < s.size() && abse <= 1 && late <= 2;){
            if(s[i] == 'A'){
                abse++;
            }else if(s[i] == 'L'){
                while(i < s.size() && s[i] == 'L'){
                    late++;
                    i++;
                    if(late >= 3) break;
                }
                late = late >= 3 ? 3 : 0;
                i--;
            }
            i++;
        }
        return abse <= 1 && late <= 2;
    }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.