4ms Accept C code


  • 11
    H

    Hopefully a nice balance of readability and performance.

    The Code:

    bool isIsomorphic(char* s, char* t) {
    		char mapST[128] = { 0 };
    		char mapTS[128] = { 0 };
    		size_t len = strlen(s);
    		for (int i = 0; i < len; ++i)
    		{
    			if (mapST[s[i]] == 0 && mapTS[t[i]] == 0)
    			{
    				mapST[s[i]] = t[i];
    				mapTS[t[i]] = s[i];
    			}
    			else
    			{
    				if (mapST[s[i]] != t[i] || mapTS[t[i]] != s[i])
    					return false;
    			}
    		}
    		return true;    
    }

  • 0
    J

    Nice solution !


Log in to reply
 

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