JavaScript Solution O(1)


  • 0
    S
    /**
     * @param {string} word
     * @return {boolean}
     */
    var detectCapitalUse = function(word) {
        if(word.toUpperCase() === word){
            return true;
        }
        
        if(word.toLowerCase() === word){
            return true;
        }
        
        if(word.substring(0,1).toUpperCase()+word.substring(1).toLowerCase() === word){
            return true;
        }
        
        return false;
    };
    

Log in to reply
 

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