Simple java Solution


  • 0
    P
    class Solution {
        public boolean detectCapitalUse(String word) {
            
            if (word.length()==1){
                return true;
            }
            
            boolean capital=false;
            
            if ((Character.isUpperCase(word.charAt(0))==true)){            
                if (Character.isUpperCase(word.charAt(word.length()-1))){                
                    capital=true;                
                }else capital=false;            
            }
            
            for (int i=1;i<word.length();i++){            
                if (Character.isUpperCase(word.charAt(i))!=capital){
                    return false;
                }          
            }
            return true;
        }
    }
    

Log in to reply
 

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