Java AC Solution By Using boolean :)


  • 0
    S
    public class Solution {
        public boolean detectCapitalUse(String word) {
            if(word.length() <= 1) return true;
            char[] w = word.toCharArray();
            int i = 0;
            boolean isUpper = false;
            if(Character.isUpperCase(w[0])) i = 1;
            if(Character.isUpperCase(w[i])) isUpper = true;
            for(; i < w.length; i++){
                if(isUpper != Character.isUpperCase(w[i])) return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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