c++ 6ms


  • 0
    S
    class Solution {
    public:
        bool detectCapitalUse(string word) {
            if(word.size() <= 1)
                return true;
            
            if(islower(word[0]) && isupper(word[1]))
                return false;
                
            for(int i = 1; i < word.size(); ++i)
            {
                if(islower(word[1]) != islower(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.