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;
}
												

最新文章

  1. IOS的Crash情况在Crashlytics平台上统计解决方案的一点遗憾(截止到2015年6月14日)
  2. Python中通过cx_Oracle访问数据库遇到的问题总结
  3. this指针基础介绍
  4. [terry笔记]Oracle10g/11g安装-redhat5.5
  5. 使用PHP获取汉字的拼音(全部与首字母)
  6. ExtJS4 动态加载
  7. 常用的bat命令
  8. Altium Designer规划电路板
  9. Android应用盈利广告平台的嵌入方法详解
  10. 【应用】Markdown 在线阅读器
  11. 我的Python成长之路---第三天---Python基础(13)---2016年1月16日(雾霾)
  12. JForum2.1.9 安装过程
  13. 以太坊开发DApp实战教程——用区块链、星际文件系统(IPFS)、Node.js和MongoDB来构建电商平台(一)
  14. python3学习笔记2---引用http://python3-cookbook.readthedocs.io/zh_CN/latest/2
  15. MySQL提示“too many connections”的解决办法
  16. 变量类型、构造器、封装以及 LeetCode 每日一题
  17. django查询数据库无法过滤月份的解决
  18. 4.2 explain 之 select_type
  19. CF1099F Cookies
  20. Vue:$set和$delete

热门文章

  1. 【BZOJ2733】永无乡(线段树,启发式合并)
  2. JS中的call()和apply()方法区别
  3. hihoCoder #1055 : 刷油漆 [ 树形dp ]
  4. msp430入门编程40
  5. Shell脚本的编写,sed的使用以及一些正则表达式
  6. PHP错误处理函数set_error_handler()的用法[转载]
  7. MAC地址泛红攻击
  8. python字符串连接方法效率比较
  9. 机器学习技法总结(五)Adaptive Boosting, AdaBoost-Stump,决策树
  10. activiti自己定义流程之自己定义表单(一):环境配置