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 思路:将单词转换为大写得到up,将单词转换为小写得到low,若word与up或与low相等,则返回true,
否则去掉word的首字母得到last,若last转换为小写后仍与last相等,则返回true,
否则返回false。
public boolean detectCapitalUse(String word) {
int len=word.length();
String up = word.toUpperCase();
String low = word.toLowerCase();
if (word.equals(up) || word.equals(low))
return true;
String last = word.substring(1, len);
if (last.toLowerCase().equals(last))
return true;
return false;
}
												

520. Detect Capital(检测数组的大小写)的更多相关文章

  1. 520 Detect Capital 检测大写字母

    给定一个单词,你需要判断单词的大写使用是否正确.我们定义,在以下情况时,单词的大写用法是正确的:    全部字母都是大写,比如"USA".    单词中所有字母都不是大写,比如&q ...

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

  7. 520. Detect Capital

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

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

  9. LeetCode 520 Detect Capital 解题报告

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

随机推荐

  1. [NOIP2000] 提高组 洛谷P1018 乘积最大

    题目描述 今年是国际数学联盟确定的“2000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一个好朋友XZ也有幸得 ...

  2. web移动端小tip,box-flex

    1,移动端页面 最重要的标签: <meta content="width=device-width,initial-scale=1.0,minimum-scale=1,maximum- ...

  3. 前端学习之- Ajax

    Ajax:页面不做刷新,直接将数据悄悄提交到后台,然后通过回调函数处理返回结果. $.Ajax({ # 提交到后台 url:'/host', # 提交到哪里 type:'POST' # 提交方式 da ...

  4. 【搜索引擎】Solr最新安装以及通过关系型数据库(MySQL,Oracle,PostgreSQL)导入数据

    版本号 最新的solr版本 : Solr 8.1.1下载地址:https://lucene.apache.org/solr/downloads.html solr-8.1.0.tgz for Linu ...

  5. Fibonacci--poj3070(矩阵快速幂)

    http://poj.org/problem?id=3070 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn ...

  6. 10-JS的函数学习

    <html> <head> <title>js的函数学习</title> <meta charset="UTF-8"/> ...

  7. Linux 将一般的用户加入sudo组is_not_in_the_sudoers_file._This_incident_will_be_reported解决方法

      在一般用户下执行sudo命令提示xxx is not in the sudoers file. This incident will be reported.解决方法:        $where ...

  8. webpack-Modules(模块)

    模块(Modules) 在模块化编程中,开发者将程序分解成离散功能块(discrete chunks of functionality),并称之为模块. 每个模块具有比完整程序更小的接触面,使得校验. ...

  9. Codeforces 344B Simple Molecules

    #include<bits/stdc++.h> using namespace std; int main() { int a,b,c; scanf("%d%d%d", ...

  10. 简单了解eMMC

    以下只是个人看法,有不妥之处,请批评指出. 参考资料:http://www.veryarm.com/1200.html 一.eMMC的发展 ROM→NorFlash→NandFlash→eMMC→UF ...