Java Iterative Solution


  • 0
    R
    
    class Solution {
        public boolean checkRecord(String s) {
            int absent=0,late=0;
            for(int i=0;i<s.length();i++){
                if(s.charAt(i) == 'A') {
                    absent++;
                    if(absent > 1) return false;
                }
                if(s.charAt(i) == 'L') {
                    late++;
                    if(late > 2) return false;
                }
                else late=0;
            }
            return true;
        }
    }
    
    

Log in to reply
 

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