Simple C Solution


  • 1
    bool detectCapitalUse(char* word) {
        bool capitalValid = isupper(word[0]);
        for(int i=1; i<strlen(word); ++i){
            if(capitalValid){
                if(!isupper(word[i])) {
                    if(i>1){
                          return false;      
                    }else{
                        capitalValid = false;
                    }
                }
            }else{
                if(isupper(word[i])) return false;
            }
        }
        
        return true;
    }
    

Log in to reply
 

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