Java 10-liner


  • 0
    X
            if (word == null || word.length() <= 1) return true;
            char[] chars = word.toCharArray();
            
            if (chars[0] >= 'a' && chars[0] <= 'z' && chars[1] >= 'A' && chars[1] <= 'Z') return false;
            boolean isAllUpper = Character.isUpperCase(chars[0]) && Character.isUpperCase(chars[1]);
            
            for (int i = 2; i < chars.length; i++) {
                boolean isUpper = Character.isUpperCase(chars[i]);
                if (isUpper ^ isAllUpper) return false;
            }
            return true;
    
    

Log in to reply
 

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