What are isomorphic strings

Problem:

Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg", "add", return true.
Given "foo", "bar", return false.
Given "paper", "title", return true.
Grade:
You may assume both s and t have the same length.

Main idea:

For two strings s and t, determine whether they are isomorphic.
If the letters in s can be replaced by those in t, then the two strings are said to be isomorphic.
All letters displayed must be replaced by other letters in their original order. Two letters are different to substitute for the same letter, but one letter can substitute for itself.
Example:
returns "egg", "add" and returns true.
returns "foo", "bar" and returns faalse.
specifies "paper" and "title" and returns true.
Note:
You can assume that the lengths of s and t are the same.

Ideas:

The meaning of this question is to replace the original string letter, the letter that appears multiple times, and the letter that replaces it must appear multiple times and appear in the original position.

Speaking of letters, I still think about judging by counting numbers. Iterate through the string to record the number of times each letter occurred. Since it is not said that these are all lowercase letters, the capacity of the number of records array should be larger because the two strings are the same length. So it is enough to drive in a loop.

After recording, run through the string again and assess whether the letters are identical in the corresponding positions in the two strings.

However, there is another problem: a test case of "abba" and "abab" occurred while sending. In this case, the number of letters is displayed the same, but the position is slightly different. To solve this problem, you need to create two more array records. The sum of the sequence numbers of the positions where the corresponding letters appear in the two character strings, only the sum of the positions where the corresponding letters appear is the same, they can be completely isomorphic.

Code (Java):

Collection: https: //github.com/Cloudox/LeetCode-Record


Show author home page