Using HashCode....e..java solutions,take a look at it..


  • 0
    S
    public class Solution {
        public boolean detectCapitalUse(String word) {
    			boolean flag=false;
    		if(word.hashCode()==word.toUpperCase().hashCode()||word.hashCode()==word.toLowerCase().hashCode())
    			flag= true;
    		else if(!flag&&(word.substring(0,1).toUpperCase() + word.substring(1).toLowerCase()).hashCode()==word.hashCode()){
    			flag=true;
    		}
    		return flag;
            
        }
    }
    

Log in to reply
 

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