Simple Java solution


  • 0
    D
    public class Solution {
        public boolean checkRecord(String s) {
            boolean absent = false;
            int continuousL = 0;
            char[] letters = s.toCharArray();
            for(char letter : letters){
                if(letter=='L'){
                    if(continuousL==2){
                        return false;
                    }
                    continuousL++;
                    continue;
                }
                continuousL=0;
                if(letter=='A'){
                    if(absent){
                        return false;
                    }
                    absent = true;
                }
            }
            return true;
        }
    }
    

Log in to reply
 

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