leetcode 520.检测大写字母
给定一个单词,你需要判断单词的大写使用是否正确。
我们定义,在以下情况时,单词的大写用法是正确的:
全部字母都是大写,比如"USA"。
单词中所有字母都不是大写,比如"leetcode"。
如果单词不只含有一个字母,只有首字母大写, 比如 "Google"。
否则,我们定义这个单词没有正确使用大写字母。
class Solution {
public boolean detectCapitalUse(String word) {
boolean firstUp = false;
int uplen = 0;
for(int i=0;i<word.length();i++){
if(word.charAt(i)<‘a‘){
if(i==0){
firstUp = true;
}
uplen++;
}
}
return (firstUp==true&&uplen==1)||uplen==word.length()||(uplen==0);
}
} 相关推荐
jiangchuanze 2019-11-04
kuoying 2020-01-23
韩学敏 2019-12-28
86403969 2019-10-23
qidu 2019-10-21
chunjiekid 2019-06-11
晨曦 2010-12-21
haleyyan 2012-06-13
Dansha的花果山 2011-06-21
ys0 2012-07-12
pikachu 2019-04-26
pythoning 2015-07-02
pythonjw 2018-11-28
MySQLl 2019-04-08
zhangwei0php 2013-11-07