[LC] 520. Detect Capital
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, 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 boolean detectCapitalUse(String word) {
int numCap = 0;
int i = 0;
while (i < word.length()) {
if (Character.isUpperCase(word.charAt(i))) {
numCap += 1;
}
i += 1;
}
if (Character.isUpperCase(word.charAt(0))) {
return numCap == 1 || numCap == word.length();
}
return numCap == 0;
}
}
[LC] 520. Detect Capital的更多相关文章
- 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 发现大写词 (字符串)
Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...
- 【leetcode】520. Detect Capital
problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写.全是小写.首字母大写,这三种情况返回True;否则返回False; solution: class ...
- 520. Detect Capital判断单词有效性
[抄题]: Given a word, you need to judge whether the usage of capitals in it is right or not. We define ...
- 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the ...
- LeetCode - 520. 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 Detect Capital 解题报告
题目要求 Given a word, you need to judge whether the usage of capitals in it is right or not. We define ...
- [LeetCode&Python] Problem 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...
随机推荐
- List、Set和Map详解及其区别和他们分别适用的场景
Java中的集合包括三大类 它们是Set(集).List(列表)和Map(映射),它们都处于java.util包中,Set.List和Map都是接口,它们有各自的实现类.Set的实现类主要有HashS ...
- D语言-运算符
Part 0:概念 表达式:表达式是由非赋值运算符或特殊运算符和值组成的,每个表达式都可以计算出一个值 Part 1:非赋值运算符 §1.1 基本的运算符 基本的运算符有+,-,*,/,% 我相信你除 ...
- windows 10下的python开发环境
linux子系统 按照文档 https://www.jianshu.com/p/2bcf5eca5fbc 的前五步,完成 ubuntu子系统安装. 不需安装图形桌面,无使用价值. 在https://w ...
- SoapUI substring
- Linux--Centos7开机启动 mysql5.7.19
参考:http://www.cnblogs.com/Anker/p/3551508.html
- PHPCMS 1分钟快速搭建
一.下载CMS源码 https://www.yzmcms.com/xiazai 下载完成后得到一个这样的压缩包 接着下载PHPStudy,安装只要一直点下一步就可以了 安装完成后打开,如下图启动两个地 ...
- Python批量重命名文件
批量替换文件名中重复字符: # -*- coding: UTF-8 -*- import os path = raw_input("请输入文件夹路径:") oldname = ra ...
- dozer
1.简介 dozer是用来两个对象之间属性转换的工具,有了这个工具之后,我们将一个对象的所有属性值转给另一个对象时,就不需要再去写重复的set和get方法了. 2.如果两个类之间的属性有些属性意思一样 ...
- 65)STL中string的知识
1)代码展示: string是一个类,只不过封装了 char* 而且还封装了 很多的字符串操作函数 2)string类的初始化: string的构造函数 ² 默认构造函数: string(); ...
- MyBatis从入门到精通(第9章):Spring集成MyBatis(中)
MyBatis从入门到精通(第9章):Spring集成MyBatis(中) 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法.应该将应用自身的设计和具体 ...