Self Explanatory Java Code


  • 0
    A
    public boolean detectCapitalUse(String word) {
            
            
            String firstLetter = word.substring(0,1);
            String restLetter = word.substring(1);
            
            boolean isCaseOne = word.equals(word.toUpperCase());
            boolean isCaseTwo = word.equals(word.toLowerCase());
            
            
            boolean isFistLetterUpperCase = firstLetter.equals(firstLetter.toUpperCase());
            
            boolean isrestLetterinLowerCase = restLetter.equals(restLetter.toLowerCase());
            
            boolean isCaseThree = isFistLetterUpperCase && isrestLetterinLowerCase;
            
            return (isCaseOne || isCaseTwo || isCaseThree);
        }
    

Log in to reply
 

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