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, 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的更多相关文章

  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. 520. Detect Capital【easy】

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

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

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

  4. 【leetcode】520. Detect Capital

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

  5. 520. Detect Capital判断单词有效性

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

  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 520 Detect Capital 解题报告

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

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

随机推荐

  1. vue简单逻辑判断

    条件判断能否显示 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  2. Codeforces Round #619 (Div. 2)E思维+二维RMQ

    题:https://codeforces.com/contest/1301/problem/E 题意:给个n*m的图形,q个询问,每次询问问询问区间最大的合法logo的面积是多少 分析:由于logo是 ...

  3. Eclipse换DarkestDark主题之后,无法使用快捷键

    问题出现: 在选用Eclipse插件的MarketPlace的时候,发现一个下载量很高的主题,看起来很不错,毫不犹豫的就下下来了. 说时迟那时快,下下来之后果然好看,不过问题也来了,快捷键失效了,Ct ...

  4. Spring framework体系架构

    Spring3.x 图中将spring分为5个部分:core.aop.data access.web.test,图中每个圆角矩形都对应一个jar,如果在maven中配置,所有这些jar的"g ...

  5. python 删除文件

    import os 删除文件: os.remove() 删除空目录: os.rmdir() 递归删除空目录: os.removedirs() 递归删除目录和文件(类似DOS命令DeleteTree): ...

  6. vzray上网教程

    1.首先按照之前的教程在chrome里安装插件-Proxy-SwitchyOmega-Chromium-2.5.15 2.打开  vzray-v3.11-windows-64,打开 3.在chrome ...

  7. PAT Basic 1017 A除以B (20) [数学问题-⼤整数运算]

    题目 本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成⽴. 输⼊格式: 输⼊在1⾏中依次给出A和B,中间以1空格分隔. ...

  8. ubuntu19.10 相关软件安装

    1.Typora Typora是一款Markdown撰写软件,Linux版本也相当好用. Typora的安装方式如下: # or run: # sudo apt-key adv --keyserver ...

  9. quartz2.2.1bug

    quartz2.1.5 调用 scheduler.start()方法时报这样一个异常: 严重: An error occurred while scanning for the next trigge ...

  10. 谷歌为何要研发新系统在5年内取代Android?

    现在的Android系统已经越做越好,体验也愈来愈佳,是唯一能和iOS掰腕子的移动操作系统.而且对于很多智能手机厂商来说,开源的Android为它们节约了太多成本,是不可或缺的基石之一.因此,想必很多 ...