Java O(N) solution beats 70.71%


  • 0
    Z

    public boolean checkRecord(String s) {

        boolean a = false;
        char[] ch = s.toCharArray();
        for(int i=0; i<s.length();i++)
        {
            if(s.charAt(i) == 'A')
            {
                if(a) return false;
                a = true;
            }
            
            if(s.charAt(i)  == 'L')
            {
                if(i>1 && s.charAt(i-1) == 'L' && s.charAt(i-2) == 'L' )
                {
                    return false;
                }
            }
        }
        
        return true;
    }

Log in to reply
 

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