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.

No two characters can map to the same character, 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:

str_1 = "egg"
str_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:

str_1 = "wow"
str_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

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade