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.

public class Solution {
public boolean detectCapitalUse(String word) {
if (word == null)
return true;
int upCnt = 0; for (int i=0; i<word.length(); i++) {
char ch = word.charAt(i);
if (ch>='A' && ch<='Z')
upCnt ++;
}
if (upCnt==word.length() || upCnt==0)
return true;
else {
if (upCnt == 1 && word.charAt(0)>='A'&&word.charAt(0)<='Z')
return true;
}
return false;
}
}

LeetCode - 520. Detect Capital的更多相关文章

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

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

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

  3. LeetCode 520 Detect Capital 解题报告

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

  4. LeetCode: 520 Detect Capital(easy)

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

  5. 【leetcode】520. Detect Capital

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

  6. 520. Detect Capital【easy】

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

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

  8. 【LeetCode】520. Detect Capital 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环判断三个条件 大写字母个数和位置判断 根据首字符 ...

  9. 520. Detect Capital

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

随机推荐

  1. 自定义alert弹框

    /**************** UIAlertControllerStyleAlert *************************/ /*创建一个 可以自定义文字颜色和字体大小的IAler ...

  2. c++---天梯赛---大笨钟

    ★题目: ★思路分析: 对可能的情况进行分类处理.在这里我把它们分成了3大类. ①不在敲钟时间 ②在敲钟时间但为整点 ③在敲钟时间且不为整点. 在敲钟时间段内我们可分别对晚8点前后进行分类讨论, 我们 ...

  3. (实用篇)使用PHP生成PDF文档

    http://mp.weixin.qq.com/s?__biz=MzIxMDA0OTcxNA==&mid=2654254929&idx=1&sn=8715d008d19af70 ...

  4. 【开发技术】 使用JSP开发WEB应用系统-------笔记

    1.主机IP地址是:localhost     or    127.0.0.1    or     实际的IP地址 2.Tomcat 服务器是一个免费的开放源代码的Web 应用服务器 3.WebRoo ...

  5. Python 3 生成手写体数字数据集

    0.引言 平时上网干啥的基本上都会接触验证码,或者在机器学习学习过程中,大家或许会接触过手写体识别/验证码识别之类问题,会用到手写体的数据集: 自己尝试写了一个生成手写体图片的python程序,在此分 ...

  6. Javascript学习--烟花

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. js_4_函数

    js的函数是怎么定义的? function 函数名(形参1,......) { 函数体: return 返回值 :                                 //  可以没有返回 ...

  8. junit设计模式--组合模式

    Composite,英语翻译下,复合,组合. 组合模式有时候又叫做部分-整体模式,它使我们在树形结构的问题中,模糊了简单元素和复杂元素的概念,客户程序可以像处理简单元素一样来处理复杂元素,从而使得客户 ...

  9. GlusterFS最佳实践

    标签(linux): glusterfs 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 今天我们来从实战中学习glusterfs 环境准备: gluster-s ...

  10. 【转】GPS定位原理

    一.距离测定原理 1.伪距测量 伪距测量是利用全球卫星定位系统进行导航定位的最基本的方法,其基本原理是:在某一瞬间利用GPS接收机同时测定至少四颗卫星的伪距,根据已知的卫星位置 和伪距观测值,采用距离 ...