public class Solution {
public boolean detectCapitalUse(String word) {
int count = 0;
String str = word.toLowerCase();
for(int i = 0; i < word.length();i++) {
if(str.charAt(i) != word.charAt(i)) {
count++;
}
}
if(count == 0 ) {
return true;
}else if(count == 1 && isCapital(word.charAt(0))) {
return true;
}else if(count == word.length()) {
return true;
}else {
return false;
}
}
public boolean isCapital(char c) {
if (c>='A' && c<='Z') {
return true;
}
return false;
}
}
520. Detect Capital
最新推荐文章于 2024-07-10 11:26:09 发布