Isomorphic String

Given two strings, determine if they are isomorphic. Two strings are "isomorphic" if each unique character from the first string can be replaced to match the second string, without changing the ordering of the characters.

Different characters must map to different characters, but a character can map to itself.

Input

  • str_1: the first string.
  • str_2: the second string.

Output

Whether if these two strings are isomorphic.

Examples

Example 1:

Input:

1str_1 = "egg"
2str_2 = "all"

Output: true

Explanation:

"e" can be replaced with "a" and "g" can be replaced with "l". Therefore, the strings are isomorphic.

Example 2:

Input:

1str_1 = "wow"
2str_2 = "aaa"

Output: false

Explanation:

"w" and "o" both maps to "a", which makes them not isomorphic.

Constraints

  • 1 <= len(str_1), len(str_2) <= 5 * 10^4
  • The strings are case sensitive and consists of valid ASCII characters.

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro