Explicit Java Solution


  • 0
    S

    public class Solution {
    public boolean detectCapitalUse(String word) {
    if(word.length()==1) return true;
    else if(Character.isLowerCase(word.charAt(0))) return checkAllLowerCase(word);
    else if(Character.isUpperCase(word.charAt(0)) && Character.isUpperCase(word.charAt(1))) return checkAllUpperCase(word);
    else if(Character.isUpperCase(word.charAt(0)) && Character.isLowerCase(word.charAt(1))) return checkAllLowerCase(word.substring(1));
    else return false;
    }
    public boolean checkAllLowerCase(String str){
    String s = str.toLowerCase();
    if(str.equals(s)) return true;
    else return false;
    }

    public boolean checkAllUpperCase(String str){
        String s = str.toUpperCase();
        if(str.equals(s)) return true;
        else return false;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.