520. Detect Capital
来源:互联网 发布:淘宝店铺地址在哪里看 编辑:程序博客网 时间:2024/06/10 02:22
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.
其实确实不难,就是我的解法实在是太繁琐了,经过师姐提点才知道原来这样解判断首字母,大写的话,再判断第二个字母,大写的话后面出现小写字母就false
小写的话后面出现大写字母就false
小写的话,后面出现大写字母就false
感谢师父看了100行我之前恶习的代码,虽然我俩都觉得逻辑没问题,但就不知道错在哪里了,,,,,,
看了《志明与春娇》和《志明与春娇2》 现在上映的为什么不叫《志明与春娇3》
bool detectCapitalUse(char* word) { int i=0; int len=strlen(word); if(('A'<=word[0])&&(word[0]<='Z')){ if(('A'<=word[1])&&(word[1]<='Z')){ for(i=2;i<len;i++){ if(('a'<=word[i])&&(word[i]<='z')){ return false; } } } else{ for(i=2;i<len;i++){ if(('A'<=word[i])&&(word[i]<='Z')){ return false; } } } return true; }else{ for(i=1;i<len;i++){ if(('A'<=word[i])&&(word[i]<='Z')){ return false; } } return true; } }
0 0
- 【Leetcode】520. Detect Capital
- 520. Detect Capital (E)
- LeetCode 520. Detect Capital
- LeetCode 520. Detect Capital
- 520. Detect Capital
- LeetCode-520. Detect Capital
- 520. Detect Capital
- leetcode 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- leetcode 520. Detect Capital
- [leetcode] 520. Detect Capital
- 520. Detect Capital Easy
- 520. Detect Capital
- [LeetCode]520. Detect Capital
- 520. Detect Capital
- 稀缺性与渴望——使用技巧
- 基于jdk和cglib实现的动态代理
- 未知性与好奇心——使用技巧
- 动态规划入门(五)
- Android 6 camera.open()异常解决方法
- 520. Detect Capital
- 损失与逃避心——使用技巧
- 博弈原理
- 剑指offer-面试题43-n个骰子的点数
- React Native学习(1):怎么快速学习一门新技术
- 程序员,如何从平庸走向理想?
- jqgrid多字段排序参数
- HttpClient简单使用之POST请求
- JS解析Json中List类型,并遍历List中的对象