class Solution {
public:
bool allCap(string word)
{
int i;
for(i=0;i<word.length();i++)
{
if(word[i]>='a'&&word[i]<='z')
break;
}
if(i==word.length())
return true;
else
return false;
}
bool allNotCap(string word)
{
int i;
for(i=0;i<word.length();i++)
{
if(word[i]>='A'&&word[i]<='Z')
break;
}
if(i==word.length())
return true;
else
return false;
}
bool onlyFirstCap(string word)
{
if(word[0]>='A'&&word[0]<='Z')
{
int i;
for(i=1;i<word.length();i++)
{
if(word[i]>='A'&&word[i]<='Z')
break;
}
if(i==word.length())
return true;
}
return false;
}
bool detectCapitalUse(string word) {
if(onlyFirstCap(word)||allCap(word)||allNotCap(word))
return true;
else
return false;
}
};
leetcode520
最新推荐文章于 2021-11-13 16:47:40 发布