力扣:520. 检测大写字母
作者:互联网
1、简单做法,将三种情况分别列出来。
class Solution {
public:
bool detectCapitalUse(string word) {
int i=1;
if(word[i]=='\0') return true;
else if(word[0]<=90&&word[0]>=65&&word[i]<=122&&word[i]>=97)
{
while(word[i]!='\0')
{
if(word[i]<=90&&word[i]>=65) return false;
++i;
}
return true;
}
else if(word[0]<=90&&word[0]>=65)
{
i=1;
while(word[i]!='\0')
{
if(word[i]<=122&&word[i]>=97) return false;
++i;
}
return true;
}
else
{
i=0;
while(word[i]!='\0')
{
if(word[i]<=90&&word[i]>=65) return false;
++i;
}
return true;
}
}
};
标签:大写字母,return,else,力扣,520,65,word,false,true 来源: https://blog.csdn.net/qq_50917103/article/details/121235556