Isomorphic Strings
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.
(判断是否为同构字符串)
Example:
1. 哈希表
用哈希表保存相同字符的index。具体实现过程如下:
1 | from collections import defaultdict |
2. zip & 集合
首先判断组成两个字符串的字符的数目是否相同,然后使用 zip
函数判断字符串相同位置的字符组合是否相同。具体实现过程如下:
1 | class Solution: |