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:

  1. All letters in this word are capitals, like "USA".
  2. All letters in this word are not capitals, like "leetcode".
  3. 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.

分析:分别判断三种条件是否满足:全大写,全小写,首字母大写;

JAVA CODE

class Solution {
public boolean detectCapitalUse(String word) {
if(word.equals(word.toUpperCase()))
return true;
if(word.equals(word.toLowerCase()))
return true;
if(word.substring(1,word.length()).equals(word.substring(1,word.length()).toLowerCase())&&(Character.toUpperCase(word.charAt(0))==word.charAt(0)))
return true;
return false;
}
}

Detect Capital的更多相关文章

  1. 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 ...

  2. LeetCode——Detect Capital

    LeetCode--Detect Capital Question Given a word, you need to judge whether the usage of capitals in i ...

  3. 520. Detect Capital【easy】

    520. Detect Capital[easy] Given a word, you need to judge whether the usage of capitals in it is rig ...

  4. Leetcode 520. Detect Capital 发现大写词 (字符串)

    Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...

  5. 【leetcode】520. Detect Capital

    problem 520. Detect Capital 题意: 题目中给出的三种情况,分别是全是大写.全是小写.首字母大写,这三种情况返回True;否则返回False; solution: class ...

  6. 520. Detect Capital

      Given a word, you need to judge whether the usage of capitals in it is right or not. We define the ...

  7. 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 ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. C# 爬虫 Jumony html解析

    前言 前几天写了个爬虫,然后认识到了自己的不足.感谢 "倚天照海- -" ,我通过你推荐的文章,意外的发现了html解析的类库——Jumony. 研究了2天,我发现这个东西简单粗暴 ...

  2. UWP 手绘视频创作工具技术分享系列

    开篇先来说一下写这篇文章的初衷. 初到来画,通读了来画 UWP App 的代码,发现里面确实有很多比较高深的技术点,同时也是有很多问题的,扩展性,耦合,性能,功能等等.于是我们决定从头重构这个产品,做 ...

  3. Semaphore实现原理分析

    synchronized的语义是互斥锁,就是在同一时刻,只有一个线程能获得执行代码的锁.但是现实生活中,有好多的场景,锁不止一把. 比如说,又到了十一假期,买票是重点,必须圈起来.在购票大厅里,有5个 ...

  4. hdu 6194 沈阳网络赛--string string string(后缀数组)

    题目链接 Problem Description Uncle Mao is a wonderful ACMER. One day he met an easy problem, but Uncle M ...

  5. jquery_mobile事件

    1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 < ...

  6. Java 强引用 软引用 弱引用 虚引用详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt393 众所周知,java中是JVM负责内存的分配和回收,这是它的优点(使用方 ...

  7. [ASP.NET MVC]笔记(二) 数据注解和验证

    验证注解的使用 1.Required:必须字段 [Required] public string FirstName() { get; set; } 2.StringLength:长度限制,或是可选项 ...

  8. 微信公众平台接口调用第一步(获取access_token)

    最近公司需要开发微信公众号,闲着无聊就写写博客,希望能帮到你我 上代码: package test; import java.util.List; import java.util.ArrayList ...

  9. 个人作业3--------个人总结(Alpha版本)

    1.问题 从第一次写博客开始,就开始意识到自己所犯的错误了,助教提醒命名规范的问题,还给了Java编码规范的链接,让自己以后能注意到这些问题. 对设计的需求分析需要团队一起,一开始分配任务是给个人分配 ...

  10. 团队作业10——Beta版本事后诸葛亮

    事后诸葛亮分析 1.总结的提纲内容: a. 项目管理之事后诸葛亮会议. 一.设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们的软件要解决的是教师需要 ...