Detect Capital(leetcode)
来源:互联网 发布:c语言定义结构体数组 编辑:程序博客网 时间:2024/05/21 09:17
Detect Capital
- Detect Capital
- 题目
- 解决
题目
leetcode题目
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 len = word.length(); int upper = 0; int lower = 0; for (int i = 0; i < len; i++) { if (word[i] >= 'A' && word[i] <= 'Z') { // word首字母大写或word中到目前为止都是大写字母 if (i == 0 || lower == 0) { upper++; } else { return false; } } else if (word[i] >= 'a' && word[i] <= 'z') { lower++; if (upper > 1) { return false; } } } return true; }};
阅读全文
0 0
- 【Leetcode】520. Detect Capital
- LeetCode 520. Detect Capital
- leetcode-520-Detect Capital
- LeetCode 520. Detect Capital
- LeetCode: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之Detect Capital
- LeetCode 520. Detect Capital
- 元数据嵌入对于用户和项目冷启动推荐系统
- VM装linux系统时,启动黑屏。
- 局部权值线性回归算法
- [LeetCode] Water and Jug Problem
- 装系统活动的总结
- Detect Capital(leetcode)
- 职业发展百问之第一问:三十岁了再进入IT行业还有机会吗?
- 围城&平凡的世界札记
- Service的onStartCommand()方法返回值详解
- PDFMate PDF Converter Professional(PDF转换工具)官方中文版V1.85下载 | 无需pdfmate pdf converter注册码
- 浅谈哈夫曼树的构建、遍历、编码
- H 子段求和(51Nod 1081)
- Asp.Net中ajax+ashx使用详解
- RabbitMQ入门教程(八):远程过程调用RPC