You are given two strings, s and t, of the same length. They are isomorphic if you can get t from s by replacing characters, with these rules:
- Every copy of one character in
s is replaced by the same character.
- Two different characters in
s can never be replaced by the same character.
- A character may be replaced by itself.
Return true if the strings are isomorphic. Otherwise return false.
Examples
Example 1:
Input: s = "moon", t = "good"
Output: true
Explanation: m becomes g, o becomes o, and n becomes d. Each letter always maps to the same letter.
Example 2:
Input: s = "abc", t = "xyx"
Output: false
Explanation: Both a and c would have to become x, which is not allowed.
Example 3:
Input: s = "xyzx", t = "abca"
Output: true
Explanation: x -> a, y -> b, z -> c, and the last x -> a again.