C++ solution


  • 0
    Y
    class Solution {
    public:
        bool detectCapitalUse(string word) {
            if(word[0]>='A' && word[0]<='Z'){
                int lower=0;
                int upper=0;
                for(int i=1;i<word.size();i++){
                    if(word[i]>='a' && word[i]<='z')
                        lower++;
                    else
                        upper++;
                }
                return lower==word.size()-1||upper==word.size()-1;
            }
            else{
                for(int i=1;i<word.size();i++){
                    if(word[i]>='A' && word[i]<='Z')
                        return false;
                }
                return true;
            }
            
        }
    };
    

Log in to reply
 

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