My Java Solution


  • 0
    R
    public static boolean detectCapitalUse(String word) {
    		char[] chars = word.toCharArray();
    
    		int upperCount = 0;
    		int lowerCount = 0;
    
    		for (int i = 0; i < chars.length; i++) {
    
    			int cCode = chars[i];
    
    			if(isUpper(cCode)) {
    				upperCount ++;
    			} else {
    				lowerCount ++;
    			}
    		}
    
    		boolean isCaptial = false;
    		
    		if((isUpper(chars[0]) && (upperCount == 1 || upperCount == chars.length)) ||
    				lowerCount == chars.length) {
    			isCaptial = true;
    		} 
    
    		return isCaptial;
    	}
    
    	public static boolean isUpper(int k) {
    		if (k >= 65 && k <= 90) {
    			return true;
    		}
    
    		return false;
    	}

Log in to reply
 

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