class Solution {
public:
bool detectCapitalUse(string word)
{
if(word.size()==1)
return true;
string high,low,other;
for(int i=0;i<word.size();i++)
{
high+=toupper(word[i]);
low+=tolower(word[i]);
if(i==0)
other+=toupper(word[i]);
else
other+=tolower(word[i]);
}
return word==high||word==low||word==other;
}
};
bool detectCapitalUse(string word)
{
if (word.size() < 2) return true;
bool flag_first = isupper(word[0]);
bool flag_second = isupper(word[1]);
if (!flag_first && flag_second) return false;
for (int i = 2; i < word.size(); i++)
{
bool flag_cur = isupper(word[i]);
if (flag_second != flag_cur) return false;
}
return true;
}