LeetCode p205 Isomorphic Strings 题解
1.题目:
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.
题意:
输入两个字符串,判断一个是否他们是否同构,及字符能够完全映射。
2.解题思路:
记录每个字符上次出现的位置,比较。
// ASCII 256个
3.代码
1 |
|