Java solution use 29ms, beats 86%


  • 0
    C
    
    public boolean detectCapitalUse(String word) {
            boolean isUpperLetter = false;
    	for (int i = 0; i < word.length(); i++) {	
    		if (word.charAt(i) >= 'A' && word.charAt(i) <= 'Z') {
    			if (i > 0) {
    				if (!isUpperLetter) {
    					return false;
    				}
    			}
    			isUpperLetter = true;
    		}
    		else {
    			if (isUpperLetter && i > 1) {
    				return false;
    			}
    			isUpperLetter = false;
    		}
    	}
            return true;
        }

Log in to reply
 

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