Sharing my C easy Solution


  • 0
    A
    char alphabet[128];
    char alphabet2[128];
    int  isIsomorphic(char* s, char* t)
    {
     int i = 0;
     int index;
     int index2;
    
     if (strlen(s)!=strlen(t))
        return false;
    
    memset(alphabet,0,sizeof(alphabet));
    memset(alphabet2,0,sizeof(alphabet));
    
    for (i=0;i<strlen(s);i++)
    {
        index = s[i];
        if (alphabet[index] == 0)
        {
            alphabet[index] = t[i];
        }
        else if (alphabet[index] == t[i])
            continue;
        else
            return false;
    }
    for (i=0;i <strlen(t);i++)
    {
        index = t[i];
        if (alphabet2[index] == 0)
        {
            alphabet2[index] = s[i];
        }
        else if (alphabet2[index] == s[i])
            continue;
        else
            return false;
    }
    return true;
    }

Log in to reply
 

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