My Java Solution


  • 0
    G
    	boolean isoMorphic = false;
    	 if(s==null ||t==null) {
    		 return isoMorphic;
    	 }
    	
    	char sArray[] = s.toCharArray();
    	
    	String value;
    	char tArray[] = t.toCharArray();
    	Map <String,String> keshav = new HashMap<String,String>();
    	
    	if (sArray.length==0 && tArray.length==0) {
    		isoMorphic = true;
    		return isoMorphic;
    	}
    	
    	
    	if (sArray.length!=tArray.length) {
    		isoMorphic = false;
    		return isoMorphic;
    	}
    	
    	for(int i=0;i<sArray.length;i++) {
    		isoMorphic = true;
    		if(keshav.containsKey(sArray[i]+"")) {
    			value  = keshav.get(sArray[i]+"");
    			if(value!=null && value.length()==1 &&  value.charAt(0)!=tArray[i]) {
    				isoMorphic = false;
    				break;
    			}
    		} 
    		
    		else {
    			value = tArray[i]+"";
    			if(keshav.containsValue(value)) {
    				isoMorphic = false;
    				break;
    			}
    			else {
    				keshav.put(sArray[i]+"",tArray[i]+"");
    			}    			
    		}
    	}
    	
    	
    	
    	return isoMorphic;

Log in to reply
 

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