C++ solution 6ms easy understand


  • 0
    Y
        bool detectCapitalUse(string word) {
            if (word.size()==1) return true;
            int i;
            if (isupper(word[0])) 
            {
                for (i = 1; i < word.size()-1; ++i)
                {
                    if (islower(word[i]) && islower(word[i+1])) continue;
                    if (isupper(word[i]) && isupper(word[i+1])) continue;
                    return false;
                }
            }else
            {
                for (i = 0; i < word.size()-1; ++i)
                {
                    if (islower(word[i]) && islower(word[i+1])) continue;
                    return false;
                }
            }
            return (i==(word.size()-1)?true:false);
        }
    

Log in to reply
 

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