551. Student Attendance Record I

T: O(n)

S: O(1)

class Solution {
    public boolean checkRecord(String s) {        
        int aCount = 0;
        for (char c : s.toCharArray()) {
            if (c == 'A') {
                aCount++;
                if (aCount >= 2) {
                    return false;
                }
            }
        }
        return !s.contains("LLL");
    }
}

/*
The student was absent ('A') for strictly fewer than 2 days total.
The student was never late ('L') for 3 or more consecutive days.


A count < 2
L no 3 consecutive days

*/

Last updated