520 Detect Capital 检测大写字母
给定一个单词,你需要判断单词的大写使用是否正确。
我们定义,在以下情况时,单词的大写用法是正确的:
全部字母都是大写,比如"USA"。
单词中所有字母都不是大写,比如"leetcode"。
如果单词不只含有一个字母,只有首字母大写, 比如 "Google"。
否则,我们定义这个单词没有正确使用大写字母。
示例 1:
输入: "USA"
输出: True
示例 2:
输入: "FlaG"
输出: False
注意: 输入是由大写和小写拉丁字母组成的非空单词。
详见:https://leetcode.com/problems/detect-capital/description/
C++:
class Solution {
public:
bool detectCapitalUse(string word) {
int cnt=0;
for(char c:word)
{
if(c<='Z')
{
++cnt;
}
}
return cnt==0||cnt==word.size()||(cnt==1&&word[0]<='Z');
}
};
520 Detect Capital 检测大写字母的更多相关文章
- Leetcode 520. Detect Capital 发现大写词 (字符串)
Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...
- [LeetCode] Detect Capital 检测大写格式
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- Leetcode520Detect Capital检测大写字母
给定一个单词,你需要判断单词的大写使用是否正确. 我们定义,在以下情况时,单词的大写用法是正确的: 全部字母都是大写,比如"USA". 单词中所有字母都不是大写,比如"l ...
- Java实现 LeetCode 520 检测大写字母
520. 检测大写字母 给定一个单词,你需要判断单词的大写使用是否正确. 我们定义,在以下情况时,单词的大写用法是正确的: 全部字母都是大写,比如"USA". 单词中所有字母都不是 ...
- 50. leetcode 520. Detect Capital
520. Detect Capital Given a word, you need to judge whether the usage of capitals in it is right or ...
- 520. Detect Capital【easy】
520. Detect Capital[easy] Given a word, you need to judge whether the usage of capitals in it is rig ...
- 【leetcode】520. Detect Capital
problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写.全是小写.首字母大写,这三种情况返回True;否则返回False; solution: class ...
- [Swift]LeetCode520. 检测大写字母 | Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
- 力扣(LeetCode)520. 检测大写字母
给定一个单词,你需要判断单词的大写使用是否正确. 我们定义,在以下情况时,单词的大写用法是正确的: 全部字母都是大写,比如"USA". 单词中所有字母都不是大写,比如"l ...
随机推荐
- http权威指南(一)-Http概述
Http概述 在Web中,不管是浏览器还是server都是通过Http相互通信的.那么Http是怎样工作的呢? 首先,client向server发送Http请求,server会在Http响应中回送所请 ...
- 一个UserState(WCF)的小例子
练习WCF的时候,遇到了一个异步调用(也许是)的问题.后来使用了重载参数UserState试着解决了一下,但不是很清楚这个参数的其他用途.现在贴出这个例子. Service部分: 客户端后台调用部分: ...
- QT实现FTP服务器(二)
QClientThread类的实现: #include "QClientThread.h" #include <QDebug> /******************* ...
- IE67 下 setattribute class 失效
解决办法.将class 换成 className ,同理.ff不能识别className,将其换成class element.setAttribute("class"," ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- jquery 获取radio被选中的值
<html> <head> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"& ...
- 一步一步学Silverlight 2系列(11):数据绑定
概念 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- random和string模块
random模块import randomprint(random.random()) #随机打印一个浮点数print(random.randint(1,5)) #随机打印一个整数,包括5print( ...
- hdu-5719 Arrange(组合数学)
题目链接: Arrange Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- Eclipse慢慢学会的快捷键
Java编辑器 添加单个import Ctrl+Shift+M Java编辑器 组织多个import Ctrl+Shift+O Ctrl+M切换窗口的大小 Ctrl+D删除当前行 ---------- ...