Detect Capital问题及解法
来源:互联网 发布:淘宝潮流女装店铺 编辑:程序博客网 时间:2024/06/18 15:08
问题描述:
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".
示例:
Input: "USA"Output: True
Input: "FlaG"Output: FalseNote: The input will be a non-empty word consisting of uppercase and lowercase latin letters.
问题分析:
我们可以统计单词中小写字母的数目,最后根据小写字母数目来进行判断。
过程详见代码:
class Solution {public: bool detectCapitalUse(string word) { if(word.length() < 2) return true; int lower = 0; int len = word.length(); for(int i = 0;i < len; i++) { if(islower(word[i])) lower++;}if(islower(word[0])) return lower == len;else return lower == len - 1 || lower == 0 ; }};
0 0
- Detect Capital问题及解法
- leetcode[Detect Capital]//待整理多种解法
- LeetCode 520. Detect Capital 自己的解法
- Leetcode之Detect Capital 问题
- 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
- 详解log4j2(下)
- Python模块random
- SpringMVC RestFul方式提交
- 我记得
- scala的传值参数和传名参数
- Detect Capital问题及解法
- 《Effective java 第2版》读书笔记--异常、并发与序列化
- 普通对象(不包括数组对象、Class对象)的创建
- Python练习题目1
- java大数处理hdu1002
- WEB骇客网
- Eclipse/Myeclipse中查看和调试JDK1.8源代码的方法
- bootstrap常用类名
- 使用Android原生的Api进行GPS定位获取位置信息