一共有三种正确的大写用法:
1)全小写(apple)
2)全大写(APPLE)
3)首字母大写(Apple)
配合使用toLowerCase()、toUpperCase()、equals(),非常简单
class Solution {
public boolean detectCapitalUse(String word) {
// 全小写
if (word.toLowerCase().equals(word)) {
return true;
}
// 全大写
if (word.toUpperCase().equals(word)) {
return true;
}
// 首字母大写
if (Character.isUpperCase(word.charAt(0))) {
String suffix = word.substring(1);