Run
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool areIsomorphic (char *str1, char *str2)
{
// If the length of the strings
// are not equal
if (strlen (str1) != strlen (str2))
{
return false;
}
// Initialise two arrays
int arr1[256] = { 0 }, arr2[256] = {0};
// Traversing both the strings
for (int i = 0; i < strlen (str1); i++)
{
// If current characters don't map
if (arr1[(int) str1[i]] !=arr2[(int) str2[i]])
{
return false;
}
// Increment the count of characters
// at their respective ASCII indices
arr1[(int) str1[i]]++;
arr2[(int) str2[i]]++;
}
return true;
}
// Driver Code
int main ()
{
char s1[] = "aab", s2[] = "xxy";
if (areIsomorphic (s1, s2))
printf ("Yes\n");
else
printf ("No\n");
return 0;
}
Login/Signup to comment