Simple Java Solution


  • 0
    X
    class Solution {
        public boolean detectCapitalUse(String word) {
            if(word.equals(word.toUpperCase()) || word.equals(word.toLowerCase())) return true;
            String firstLetter = word.substring(0,1);
            String remainLetters = word.substring(1);
            return firstLetter.equals(firstLetter.toUpperCase()) && remainLetters.equals(remainLetters.toLowerCase());
        }
    }
    

Log in to reply
 

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