Java 23-Liner :D


  • 0
    K
    public class Solution {
        public boolean detectCapitalUse(String word) {
            int len = 0;
            boolean first = false;
            for(int i = 0; i < word.length(); ++i)
            {
                if(isCapital(word.charAt(i))){
                    ++len;
                    if(i == 0) first = true;
                } 
            }
            if(len ==0 || len == word.length()||(first&&len==1))
            {
                return true;
            }
            return false;
        }
        
        private boolean isCapital(char c)
        {
            return c>='A' && c <= 'Z';
        }
    }
    

Log in to reply
 

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