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

最新文章

  1. mysql高并发和表类型
  2. ASP.NET Web API自身对CORS的支持: CORS授权检验的实施
  3. JS 面向对象随笔
  4. SQL Server 常用日期查询语句
  5. 一个简单的MySql数据库连接池的实现
  6. [ json editor] 如何在网页中使用Json editor 插件
  7. nanoTime对volatile 测试的一种写法
  8. 【COGS】894. 追查坏牛奶
  9. ubuntu 12 JDK 编译
  10. 括弧匹配检验(check)
  11. careercup-树与图 4.8
  12. IO调度算法研究1
  13. acm的第一场比赛的总结
  14. Java中Date日期字符串格式的各种转换
  15. Scala的安装,入门,学习,基础
  16. 【转】一文掌握 Linux 性能分析之网络篇
  17. 2018牛客暑期ACM多校训练营第一场(有坑未填)
  18. PI上导入RFC
  19. Java中sort实现降序排序
  20. bootstrapValidator常用验证规则总结

热门文章

  1. CYPHER 语句(Neo4j)
  2. Restful设计相关
  3. LeetCode——623.在二叉树中增加一行
  4. 吴裕雄--天生自然Linux操作系统:Linux 文件与目录管理
  5. Java之多线程窗口卖票问题(Thread)
  6. Deep learning with Python
  7. JavaSE--压缩
  8. ant design for vue 刷新页面,根据当前路由选中相应菜单
  9. [AC自动机]玄武密码
  10. CF 1096D Easy Problem [动态规划]