码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode 520.检测大写字母

时间:2019-12-01 16:54:43      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:return   turn   ||   int   pre   tca   有一个   word   使用   

给定一个单词,你需要判断单词的大写使用是否正确。

我们定义,在以下情况时,单词的大写用法是正确的:

全部字母都是大写,比如"USA"。
单词中所有字母都不是大写,比如"leetcode"。
如果单词不只含有一个字母,只有首字母大写, 比如 "Google"。
否则,我们定义这个单词没有正确使用大写字母。

 1 class Solution {
 2     public boolean detectCapitalUse(String word) {
 3         boolean firstUp = false;
 4         int uplen = 0;
 5         for(int i=0;i<word.length();i++){
 6             if(word.charAt(i)<‘a‘){
 7                 if(i==0){
 8                     firstUp = true;
 9                 }
10                 uplen++;
11             }
12         }
13         return (firstUp==true&&uplen==1)||uplen==word.length()||(uplen==0);
14     }
15 }

 

leetcode 520.检测大写字母

标签:return   turn   ||   int   pre   tca   有一个   word   使用   

原文地址:https://www.cnblogs.com/gongzixiaobaibcy/p/11966393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!