[LeetCode] 520. Detect Capital
来源:互联网 发布:ornx奥尼克斯淘宝 编辑:程序博客网 时间:2024/06/03 18:00
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”.
Otherwise, we define that this word doesn’t use capitals in a right way.
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.
class Solution {public: bool detectCapitalUse(string word) { int HasUpper = 0, HasLower = 0; for (int i = 0; i < word.size(); i++) { HasUpper += (word[i] < 'a'); HasLower += (word[i] >= 'a'); } return (HasUpper && !HasLower) || (!HasUpper && HasLower) || ((word[0] < 'a') && HasUpper == 1 && word.size() > 1); }};
阅读全文
0 0
- 【Leetcode】520. Detect Capital
- LeetCode 520. Detect Capital
- LeetCode 520. Detect Capital
- LeetCode-520. Detect Capital
- leetcode 520. Detect Capital
- leetcode 520. Detect Capital
- [leetcode] 520. Detect Capital
- [LeetCode]520. Detect Capital
- LeetCode | 520. Detect Capital
- 【LeetCode】520. Detect Capital
- LeetCode 520. Detect Capital
- leetcode 520. Detect Capital
- LeetCode 520. Detect Capital
- [leetcode]: 520. Detect Capital
- leetcode 520. Detect Capital
- LeetCode:520. Detect Capital
- 【Leetcode】520. Detect Capital
- LeetCode: 520. Detect Capital
- 2017暑假集训第六天
- 关于Twitch视频回放录像的下载
- 识别提交
- 贪心,递归,动态规划,及分治算法之间的区别和联系(四)
- SPOJ---Query on a tree (树链剖分)
- [LeetCode] 520. Detect Capital
- epoll机制:epoll_create、epoll_ctl、epoll_wait、close用法详解
- 8月5日集训
- [PAT乙级]1060. 爱丁顿数(25)
- SQL注入#和$区别与总结
- C语言数据输入scanf( )和getchar( )
- jquery判断checkbox是否选中的3种方法
- MySQL 5.7.X 解压缩安装方法
- spring拦截器