My Simple C solution


  • 1
    J
    bool isIsomorphic(char* s, char* t)
    {
    	int i;
    	int hash[256];
    	int hash1[256]={0};
    	memset(hash,-1,sizeof(hash));
    	bool flag = true;
    	int len1 = strlen(s);
    	int len2= strlen(t);
    	if( len1 != len2 )return false;
    	for(i=0;i<len1;i++)
    	{
    		if((hash[s[i]]!=-1&&hash[s[i]]!=t[i])||(hash1[t[i]]>0)&&hash[s[i]]<0)
    		{
    			flag = false;
    			break;
    		}
    		hash[s[i]] = t[i];
    		hash1[t[i]]++;
    	}
    	return flag;
    }

Log in to reply
 

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