[JAVA] Simple Iteration Check / T : O(N), S : O(1)


  • 0
    J
    class Solution {
        public boolean checkRecord(String s) {
            int absent = 0;
            int late = 0;
            
            for(char ch : s.toCharArray()){
                if(ch == 'A'){
                    if(absent > 0)
                        return false;
                    absent++;
                    late = 0;
                }
                else if(ch == 'L'){
                    if(late > 1)
                        return false;
                    late++;
                }
                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.