Java O(n) Beat 97%


  • 0
    Y
        public boolean checkRecord(String s) {
            char[] arr = s.toCharArray();
            int countA = 0, countL = 0;
            for (char c : arr) {
                if (c == 'A') {
                    countA++;
                    countL = 0;
                } else if (c == 'L') {
                    countL++;
                } else {
                    countL = 0;
                }
                if (countA > 1 || countL > 2) {
                    return false;
                }
            }
            return true;
        }
    

Log in to reply
 

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