c++ solution


  • 0
    W
    class Solution {
    public:
        bool detectCapitalUse(string word) {
            bool firstCap=false;
    		bool secondCap=false;
    		for (int i=0;i<word.size();++i) {
    			if (i==0 && word[i]<='Z' && word[i]>='A') firstCap=true;
    			else {
    				if (i==1 && word[i]<='Z' && word[i]>='A') secondCap=true;
    				if (firstCap && secondCap && !(word[i] <= 'Z' && word[i] >= 'A')) return false;
    				if (firstCap && !secondCap && word[i] <= 'Z' && word[i] >= 'A') return false;
    				if (!firstCap && word[i] <= 'Z' && word[i] >= 'A') return false;
    			}
    		}
    		return true;
        }
    };
    
    

Log in to reply
 

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