Detect Capital
来源:互联网 发布:swift完整项目源码 编辑:程序博客网 时间:2024/05/21 01:55
https://leetcode.com/problems/detect-capital/?tab=Description
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.
bool bIsUpper(char ch) { return (ch >= 'A' && ch <= 'Z');}bool detectCapitalUse(char* word) { int len = strlen(word); int firstIsUpper = false; int i; if(len <= 1) return true; firstIsUpper = bIsUpper(word[0]); for(i = 1; i < len; i++) { if(firstIsUpper) { if(i != 1 && (bIsUpper(word[i]) != bIsUpper(word[i-1]))) break; } else { if(bIsUpper(word[i])) break; } } return (i == len)?true:false;}
0 0
- Detect Capital
- Detect Capital
- Detect Capital
- Detect Capital
- Detect Capital
- Detect Capital
- Detect Capital
- 【Leetcode】520. Detect Capital
- 520. Detect Capital (E)
- LeetCode 520. Detect Capital
- leetcode-520-Detect Capital
- LeetCode 520. Detect Capital
- leetcode520: Detect Capital
- 520. Detect Capital
- LeetCode:Detect Capital
- LeetCode-520. Detect Capital
- 【520】Detect Capital
- Leetcode #520 Detect Capital
- ES6中的promise对象
- Failed to get D-Bus connection: Operation not permitted
- 百行代码集成Emoji并转成iOS、后台可识别字符
- 二叉树的重建
- Jfinal提示java.lang.IllegalStateException: port: 80 already in use!
- Detect Capital
- Android线程池的使用方法
- 调试---2.拨号
- QT QPushButton 通过stylesheet 设置样式
- EhCache,memcache,redis知识介绍,原文地址:http://blog.csdn.net/jationxiaozi/article/details/8509732
- mysql——explain命令简介
- 竖式问题
- RxSwift使用教程
- Android NDK