my easy o(n)time c solution


  • 0
    H
    bool isIsomorphic(char* s, char* t) {
    	int a[300],b[300];
    	for (int i = 0; i<300; i++)
    	{
    	    a[i] = 1000;
    	    b[i]=1000;
    	}
    	for (int i = 0; s[i]; i++)
    	{
    		if (a[s[i]+128] == 1000)
    			a[s[i]+128] = t[i]+128;
    		if (a[s[i]+128] != t[i]+128)
    			return false;
    		if (b[t[i]+128] == 1000)
    			b[t[i]+128] = s[i]+128;
    		if (b[t[i]+128] != s[i]+128)
    			return false;
    	}
    	return true;
    }
    

Log in to reply
 

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