Java Just another way around


  • 0
    O

    Just another way around...

    public class Solution {
        public boolean detectCapitalUse(String word) {
            if (word == null || word.length() <= 1)
                return true;
            boolean first_C = get_C(word.charAt(0));
            boolean second_C = get_C(word.charAt(1));
            
            // "aA"
            if (!first_C && second_C)
                return false;
            
            char[] words = word.toCharArray();
            
            for (int i = 2; i < words.length; i++) {
                if (get_C(words[i]) != (first_C && second_C))
                    return false;
            }
            
            return true;
        }
        
        private boolean get_C(char c) {
            return (c - 'A' >= 0 && c - 'A' <= 26);
        }
    }
    

Log in to reply
 

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