Java Solution


  • 0
    class Solution {
        public boolean detectCapitalUse(String word) {
            int wordLength = word.length();
            if(wordLength < 2){
                return true;
            } 
            
            char[] charArray = word.toCharArray();
            char char0 = charArray[0];
            if(char0>97){ //First character is small
                 return word.equals(word.toLowerCase());     
            } else if(wordLength==2){ 
                return true;            
            } else { //First character is big and length is larger than 2
                if(charArray[1]<97) { //Second character is large, so should be all next
                    return ((word.substring(2)).equals(word.substring(2).toUpperCase()));
                } else {
                    return ((word.substring(2)).equals(word.substring(2).toLowerCase()));            
                }
            }
        }
        
    }
    

Log in to reply
 

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