Java Straightforward Solution O(N),no tricky stuff and Faster than 1-line code


  • 0
    S

    This easy problem comes from REAL interview!

    public class Solution {
    public boolean checkRecord(String s) {
        int A = 0;
        
        for (int i = 0; i < s.length(); i++) {
            if ((s.charAt(i) == 'A' && ++A>1) || (i<=s.length()-3 && s.substring(i,i+3).equals("LLL"))) {
                return false;
            }
        }
        return true;
    }
    

    }


Log in to reply
 

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