My C++ code, beats 80%;


  • 0
    A

    '''
    class Solution {
    public:
    bool detectCapitalUse(string word) {

    		int count = 0;
    
    		if (word.size() == 0)
    			return false;
    
    		if (word.size() == 1)
    			return true;
    
    		for (int i = 0; i < word.size(); i++)
    		{
    			if (isupper(word[i]))
    			{
    				count++;
    			}
    		}
    
    		if (count == 0)
    			return true;
    
    		if (count == word.size())
    		{
    			return true;
    		}
    
    		if (count == 1)
    		{
    			if (!isupper(word[0]))
    			{
    				return false;
    			}
    
    			else 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.