O(n) java solution


  • 0
    Z
    boolean firstCapital=false,smallSoFar = false;
    		for(int i=0;i<word.length();i++){
    			if((int)word.charAt(i) >=65 &&  (int)word.charAt(i)<=90){
    				if(i==0){
    					firstCapital=true;
    				}
    				else if (!firstCapital || (firstCapital && smallSoFar)){
    					return false;
    				}
    			}else{
    				if(firstCapital && i>1 && !smallSoFar){
    					return false;
    				}else{
    					smallSoFar=true;
    				}
    			}
    		}
    		return true;
    

Log in to reply
 

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