clueless coding // TODO: be smarter

LeetCode Student Attendance Record I: CPP Solution



TL;DR Code Solution


bool checkRecord(string s) {

    int count = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'A') {
            count++;
        }
    }

    int consecutives = 0;
    int current = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'L') {
            current++;
            consecutives = max(consecutives, current);
        }    
        else {
            current = 0;
        }

    }

    return count <= 1 && consecutives <= 2;
}