520. Detect Capital
来源:互联网 发布:淘宝卖家参加聚划算 编辑:程序博客网 时间:2024/06/05 20:09
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 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.
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.
题意
判断给定的一个字符串是否符合书写规范
规范的定义如下:
1. 所有的字母都是大写
2. 所有的首字母都是小写
3. 首字母大写
算法思路
只需要把字符串和全部大小写的比较,分隔字符串后再比较即可,难度不大
代码实现
package easy;public class DetectCapital { public boolean detectCapitalUse(String word) { return word.equals( word.toLowerCase()) || word.equals(word.toUpperCase()) || (Character.isUpperCase( word.charAt(0) ) && word.substring(1).equals(word.substring(1).toLowerCase())); }}
阅读全文
0 0
- 【Leetcode】520. Detect Capital
- 520. Detect Capital (E)
- LeetCode 520. Detect Capital
- LeetCode 520. Detect Capital
- 520. Detect Capital
- LeetCode-520. Detect Capital
- 520. Detect Capital
- leetcode 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- 520. Detect Capital
- leetcode 520. Detect Capital
- [leetcode] 520. Detect Capital
- 520. Detect Capital Easy
- 520. Detect Capital
- [LeetCode]520. Detect Capital
- 520. Detect Capital
- 腾讯2017秋招笔试编程题--素数对
- jsp中弹出窗口显示下拉框,将下拉框的值传入到另外一个页面
- Lombok 安装、入门
- 个人总结 javaIO流
- 一:Linux 简介及常用命令
- 520. Detect Capital
- glide 4.0 加载GIF 控制次数
- 浅谈服务治理与微服务
- PHP中有关于String字符串的操作
- JVM高级特性与实践(七):九大类字节码指令集(实例探究 )
- Error:Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry
- 《你不知道的JavaScript》读书笔记一
- (System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (System.Web.UI.Ht
- Linux的inode的理解