Java/520. Detect Capital 检测大写字母
程序员文章站
2022-05-15 14:06:10
...
题目
代码部分(4ms 96.41%)
class Solution {
public boolean detectCapitalUse(String word) {
char[] ch = word.toCharArray();
boolean flag1 = true; //全大写
boolean flag2 = true; //全小写
boolean flag3 = true; //首大写
for(int i = 0; i < ch.length; i++){
if('a' <= ch[i] && ch[i] <= 'z') flag1 = false;
if('A' <= ch[i] && ch[i] <= 'Z') flag2 = false;
}
if(ch[0] < 'A' && 'Z' < ch[0]) flag3 = false;
for(int i = 1; i < ch.length; i++){
if('A' <= ch[i] && ch[i] <= 'Z') flag3 = false;
}
if(flag1 || flag2 || flag3) return true;
return false;
}
}
上一篇: CTF-隐写术(三)
推荐阅读
-
520. 检测大写字母
-
LeetCode - 520 - 检测大写字母(detect-capital)
-
Java/520. Detect Capital 检测大写字母
-
[高级编程技术作业]LeetCode Problem 520. Detect Capital
-
Leetcode 520. Detect Capital (python+cpp)
-
Leetcode PHP题解--D81 520. Detect Capital
-
Leetcode PHP题解--D81 520. Detect Capital
-
520. Detect Capital
-
String:520. Detect Capital
-
【String-easy】520. Detect Capital 检查是否是Capital