Share my solution for freshman


  • 0
    C

    class Solution {
    public:
    bool detectCapitalUse(string word) {
    int cnt = 0;

        while(isupper(word[0]))
        {
            for (int i=1; i< word.size(); i++)
            {
                if(islower(word[i]))
                {
                   cnt++;
                }
                
            }
            if(cnt == 0 | cnt == word.size() - 1)
            {
            return true; 
                
            }
            else
            {
                return false;
            }
        }
       while(islower(word[0]))
       {
       for (int i=1; i< word.size(); i++)
            {
                if(islower(word[i]))
                {
                  cnt++;
                }
            }
             if(cnt == word.size() - 1)
            {
            return true; 
                
            }
            else
            {
                return false;
            }
            
       }
    }
    

    };


Log in to reply
 

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