Javascript O(N) solution


  • 0
    R

    suggestions always appreciated!

    
    const checkRecord = function(s) {
        let absent = false;
        let i;
        
        if (s.length > 1) {
            for (i = 0; i < s.length; i++) {
                if (s[i] === "A") {
                    if (!absent) { absent = true; }
                    else { return false; }
                }
                if (s[i] === "L" && s[i + 1] === "L" && s[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.