LeetCode之Detect Capital

1、题目

 

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.

Subscribe to see which companies asked this question.

 

 

 

 

2、代码实现

 

public class Solution {public boolean detectCapitalUse(String word) {if (word == null || word.length() == 0)return false;if (word.length() == 1) return true;int length = word.length();if (word.charAt(0) >= 65 && word.charAt(0) <= 90) {//AA**if (word.charAt(1) >= 65 && word.charAt(1) <= 90) {if (length > 2) {//AA*a*for (int i = 2 ; i < length; ++i) {if (word.charAt(i) >= 97 && word.charAt(i) <= 122)return false;}//AAAreturn true;} else {//AAreturn true;}}//Aa**if (word.charAt(1) >= 97 && word.charAt(1) <= 122) {if (length > 2) {for (int i = 2 ; i < length; ++i) {//Aa*A*if (word.charAt(i) >= 65 && word.charAt(i) <= 90)return false;}//Aaareturn true;} else {//Aareturn true;}} } else {//aAafor (int i = 1; i < length; i++) {if (word.charAt(i) >= 65 && word.charAt(i) <= 90)return false;}//aaareturn true;}return false;}
}

 

 

 

 

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/291269.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

你一写长文章就焦虑拖延?

这是病&#xff0c;得治。 症状 每年春季学期&#xff0c;总会有一些人很烦躁。 别人晒朋友圈&#xff0c;他留言说不中听的话&#xff1b;你见他突然妄自菲薄&#xff0c;开导劝慰他&#xff0c;却被辩驳甚至骂一通&#xff1b;一点儿小事儿&#xff0c;都能激起他胸中的愤怒&…

mysql通过data目录恢复数据库

mysql通过data目录恢复数据库 阅读&#xff1a;1236次 时间&#xff1a;2010-03-24 06:53:30 字体&#xff1a;[大 中 小]重装系统后&#xff0c;MySQL服务没有了&#xff0c;但是数据库的文件还在&#xff0c;这个时候我想恢复以前的数据库&#xff0c; 起码要把数据导出来…

5.7.21mysql数据库_【数据库】mysql5.7.21 winx64安装配置图文分享

本文主要为大家详细介绍了mysql 5.7.21 winx64安装配置方法图文教程&#xff0c;具有一定的参考价值&#xff0c;感兴趣的小伙伴们可以参考一下&#xff0c;希望能帮助到大家。1、将下载好的mysql压缩包解压到安装目录下2、新建文件my.ini&#xff0c;放置到mysql安装目录下&am…

.NET7的七项重大改进!

.NET 7 Preview1发布了&#xff0c;没时间实操&#xff1f;先快来看看.NET7的七项重大改进&#xff01;1、不再支持.NET 7应用程序、运行时和SDK的多级查找&#xff08;MLL&#xff09;2、PATH停止向.NET 7运行时和SDK添加32位.NET3、默认情况下&#xff0c; dotnet build/publ…

LeetCode之Sum of Two Integers

1、题目 Calculate the sum of two integers a and b, but you are not allowed to use the operator and -. Example: Given a 1 and b 2, return 3. Credits: Special thanks to fujiaozhu for adding this problem and creating all test cases. Subscribe to see wh…

关于新加坡IT薪酬

很多朋友发邮件或留言问我关于新加坡IT薪酬的问题&#xff0c;由于前段时间比较忙&#xff0c;所以没有及时一一回复&#xff0c;在此表示抱歉。 新加坡IT薪酬范围大概如下&#xff08;月薪,新加坡币对人民币为1:5&#xff09;: Junior Developer/Programmer/Engineer/Consulta…

Spring Boot 入门小目标 3 --- 先来试着热部署

2019独角兽企业重金招聘Python工程师标准>>> Spring Boot 入门小目标---先来试着热部署 这次写的主要就是 使用 springloaded 来实现 热部署。 很多时候&#xff0c;我们在修改和添加了新的方法或代码&#xff0c;都需要重启服务器。这样很麻烦&#xff0c;而且 不合…

三:Java之Applet

首先我要说的是Applet是一种应用程序&#xff0c;它是一种由JAVA编写的小应用程序&#xff0c;通常这样的应用程序都像他的名字一样&#xff0c;是一个非常小的程序&#xff0c;或许有些朋友就会问了&#xff0c;那么它是用来干什么的呢&#xff1f;JAVA程序就是JAVA程序啊&…

基于事件驱动架构构建微服务第19部分:使用 SignalR 和 Azure Active Directory 构建和保护实时通信...

原文链接&#xff1a;https://logcorner.com/building-micro-services-through-event-driven-architecture-part19-building-and-securing-real-time-communications-using-signalr-and-azure-active-directory/命令 HTTP API 将事件存储到事件存储&#xff0c;但不直接将它们发…

LeetCode之Maximum Depth of Binary Tree

1、题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Subscribe to see which companies asked this question. 2、代码实现 /*** Definition for a…

java 多线程之间通信_JAVA多线程之线程间的通信方式解析

JAVA多线程之线程间的通信方式解析一&#xff0c;介绍本总结我对于JAVA多线程中线程之间的通信方式的理解&#xff0c;主要以代码结合文字的方式来讨论线程间的通信&#xff0c;故摘抄了书中的一些示例代码。二&#xff0c;线程间的.通信方式①同步这里讲的同步是指多个线程通过…

Orchard之生成新模板

一&#xff1a;启用 Code Generation 进入后台&#xff0c; Modules –> Developer Enable 之。 二&#xff1a;生成模版 首先&#xff0c;进入 Orchard 命令行 在 CMD 下到达解决方案的 Web 的 Bin 目录下&#xff0c;打开 Orchard 命令&#xff0c;输入&#xff1a; code…

Java设计模式-状态模式(State)

核心思想就是&#xff1a;当对象的状态改变时&#xff0c;同时改变其行为&#xff0c;很好理解&#xff01;就拿QQ来说&#xff0c;有几种状态&#xff0c;在线、隐身、忙碌等&#xff0c;每个状态对应不同的操作&#xff0c;而且你的好友也能看到你的状态&#xff0c;所以&…

cookies,sessionStorage 和 localStorage 的区别?

cookie是网站为了标示用户身份而储存在用户本地终端&#xff08;Client Side&#xff09;上的数据&#xff08;通常经过加密&#xff09;。cookie数据始终在同源的http请求中携带&#xff08;即使不需要&#xff09;&#xff0c;记会在浏览器和服务器间来回传递。sessionStorag…

基于Prometheus的.NET 4.x应用服务监控

【.NET监控】| 总结/Edison Zhou0Why 监控&#xff1f;Edison所在团队95%以上的应用都是基于.NET 4.5开发的&#xff0c;只能跑在Windows Server服务器上的IIS中&#xff0c;公司运维也没有意愿对Windows Server进行有效的管理和提供监控支持&#xff0c;整得我们无法及时查看有…

php+对象+toarray_PHP 对象、数组间的转换

PHP 对象、数组间的转换/*** PHP 对象、数组间的转换** author flyer0126* since 2012/05/03**/// 1. 利用(array)和(object)&#xff0c;简单处理$objTemp (object)array();$objTemp->a 1;$objTemp->b 2;$objTemp->c 3;$arrTemp (array)$objTemp;print_r($objTe…

LeetCode之Happy Number

1、题目 Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process u…

高效沟通的7C原则

2019独角兽企业重金招聘Python工程师标准>>> 怎样确保沟通的顺畅和高效性呢&#xff1f;成功人士已经总结了很多方法&#xff0c;七项基本原则是一种基本的方法&#xff0c;起到了检查列表的作用&#xff0c;在你发送信息之前&#xff0c;对照检查可以帮助你确认信息…

ps切片导出时将切片选项选择为“所有用户切片”

ps切片导出时将切片选项选择为“所有用户切片”&#xff0c;可导出所有切中的区域。转载于:https://www.cnblogs.com/npk19195global/p/4513707.html

WTMPlus 1.4 Uniapp来了

点击上方蓝字关注我们1.4版本长期以来&#xff0c;WTM都是后台管理系统的开发利器&#xff0c;对于移动端支持的不够。这次WTMPlus 1.4我们加入了对UniApp的支持&#xff0c;你可以轻松的使用WTMPlus同时制作后台管理系统和各种移动端小程序了。前后台模式切换用户现在可以自由…