java Solution


  • 0
    P

    Easy to understand java code

     char[] arr = word.toCharArray();
            int n=word.length();
             boolean flag=false;
    	        if((char)arr[0]>='A' && (char)arr[0]<='Z'){
                 
                    if(n==1) return true;
                   else if((char)arr[1]>='A' && (char)arr[1]<='Z'){
                       if(n==2) return true;
                       for(int i=2;i<n;i++){
                           
                        if(i<n && (char)arr[i]>='A' && (char)arr[i]<='Z') flag=true;
                        
                        else return false; 
                    }}
                      else if(  (char)arr[1]>='a' && (char)arr[1]<='z'){
                          if(n==2) return true;
                           for(int i=2;i<n;i++){
                        
                        if(i<n && (char)arr[i]>='a' && (char)arr[i]<='z') flag= true;
                        else return false;  
                        } }
                   
                    
                    else return false;
                  }
                else if( (char)arr[0]>='a' && (char)arr[0]<='z'){
                    for(int i=1;i<n;i++){
                        if(i<n && (char)arr[i]>='a' && (char)arr[i]<='z') flag=true;
                        else return false;
                    }
                    if(n==1) return true;
                }
    	        else return false;
    	        return flag;
    

Log in to reply
 

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