Concise Java O(N) solution


  • 0
    S
    public boolean checkRecord(String s) {
        boolean absent = false;
        for (int i = 0; i < s.length(); i++) {
            char crr = s.charAt(i);
            if (crr == 'A') {
                if (absent) return false;
                absent = true;
            } else if (crr == 'L' && 
                       i > 1 && s.charAt(i - 1) == 'L' && s.charAt(i - 2) == 'L') {
                return false;
            }
        }
        return true;
    }
    

Log in to reply
 

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