【leetcode】检测大写字母

 

bool detectCapitalUse(char * word){
    bool smallFlag=false;
    int cnt=0;
    for(int i=0; i<strlen(word); i++){
        if(word[i]>='A' && word[i]<='Z'){
            cnt++;
            if(smallFlag)
                return false;
        }
        
        if(word[i]>='a' && word[i]<='z'){
            if(cnt>1)
                return false;
            smallFlag=true;
        }          
    }    
    return true;
}

 

posted @ 2020-11-20 18:42  温暖了寂寞  阅读(87)  评论(0编辑  收藏  举报