📘
Isomorphic Strings
Two strings s and t are isomorphic if the characters in s can be replaced to get t, preserving order and with a one-to-one mapping.
Return True or False.
Example:
Input:
egg add
Output:
True
Reasoning:
- We create two empty mappings to store the character relationships between
sandt. - We iterate over the characters in
sandtsimultaneously, checking if each character insmaps to a unique character int. In this case, 'e' maps to 'a', 'g' maps to 'd', and the second 'g' still maps to 'd'. - Since the mappings are consistent ('e' to 'a' and 'g' to 'd') and one-to-one, we can conclude that
sandtare isomorphic. - The final output is
True, indicating that the strings are isomorphic.
Constraints:
- 1 <= len(s) == len(t) <= 5 * 10^4
- s and t consist of ASCII characters
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.