Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.
We define the usage of capitals in a word to be right when one of the following cases holds:
- All letters in this word are capitals, like "USA".
- All letters in this word are not capitals, like "leetcode".
- Only the first letter in this word is capital, like "Google".
Input: "USA" Output: True
Input: "FlaG" Output: Falseclass Solution {
public:
bool detectCapitalUse(string word) {
int n=word.size();
int big=0,small=0;
for(int i=0;i<n;++i)
{
if(word[i]>='a'&&word[i]<='z')
++small;
else
++big;
}
if((big==0&&small==n)||(big==n&&small==0)||(word[0]>='A'&&word[0]<='Z'&&small==n-1))
return true;
else
return false;
}
};