Easy-14
来源:互联网 发布:c语言中最大公约数 编辑:程序博客网 时间:2024/06/05 06:37
leetcode 520. 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 if it has more than one letter, like "Google".
Example 1:
Input: "USA"Output: True
Example 2:
Input: "FlaG"Output: False
Note: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
WA:(未考虑字母的位置关系)
bool detectCapitalUse(char* word) {
int length=strlen(word);
int result=0;
for(int i=0;i<length;i++)
{
if(word[i]>='a'&&word[i]<='z')
{
result+=1;
}
else if(word[i]>='A'&&word[i]<='Z')
{
result+=2;
}
}
if(result==length||result==2*length||result==length+1)
{
return true;
}
else
{
return false;
}
}
AC:
bool detectCapitalUse(char* word) {
int length=strlen(word);
int result=0;
for(int i=0;i<length;i++)
{
if(word[i]>='a'&&word[i]<='z')
{
result+=1;
}
else if(word[i]>='A'&&word[i]<='Z')
{
result+=2;
}
}
if(result==length||result==2*length)
{
return true;
}
else if(result==length+1)
{
return word[0]>='A'&&word[0]<='Z';
}
else
{
return false;
}
}
- Easy-14
- easy
- Easy
- [Leetcode 14, Easy] Longest common prefix
- <LeetCode><Easy> 14 Longest Common Prefix
- Easy 14 Plus One(66)
- LeetCode-Easy刷题(14) Add Binary
- LeetCode-14-Longest Common Prefix(Number/Vector/String)-Easy
- Easy Plugs
- easy problem
- So Easy!
- so easy
- easy explorer
- Easy Explore
- Easy Task
- Easy Task
- Easy CHM
- HDU2699+Easy
- EA&UML日拱一卒--序列图(Sequence Diagram)::同步/异步
- hdu5782
- 滑动窗口的最大值
- ViewPager使用版本一
- Java_RandomAccessFile和IO流
- Easy-14
- 矩阵中的路径
- 1.docker的安装
- 机器人的运动范围
- POJ2245Lotto
- 腾讯云服务器的配置与部署(二):MySQL的配置安装、云服务器与云数据库的连接
- C++11 lambda 表达式解析
- Mysql like 用法
- unit7~~访问网络文件共享服务