Javascript solution beats 100% solutions


  • 0
    R
    var checkRecord = function(s) {
        var L = 0,
            A = 0,
            counter = 0,
            currentChar;
        
        while(counter < s.length){
            currentChar = s[counter];
            if(currentChar === 'A'){
                if(A === 1)
                    return false;
                A++;
                L = 0;
            }
            if(currentChar === 'L'){
                if(L === 2)
                    return false;
                L++;
            }
            if(currentChar === 'P'){
                L = 0;
            }
            
            counter++;
        }
        
        return true;
    };

Log in to reply
 

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