Java O(n)


  • 0
    J
    public class Solution {
        public boolean checkRecord(String s) {
            
            int countA = 0;
            int countL = 0;
            for(char c : s.toCharArray()){
                if(c == 'A'&& ++countA == 2) {
                    return false;
                }
                
                if(c == 'L'){
                    ++countL;
                    if(countL == 3)
                        return false;
                }
                else{
                    countL = 0;
                }
            }
            
            return true;
        }
    }
    

Log in to reply
 

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