205. Isomorphic Strings
题目要求的是双向关系,一开始理解错了
class IsIsomorphic {
public:
bool isIsomorphic(string s, string t) {
if (s.size() != t.size())
{
return false;
}
if (s.empty())
{
return true;
}
if (isIsomorphicCore(s, t) && isIsomorphicCore(t, s))
{
return true;
}
return false;
}
bool isIsomorphicCore(string s, string t)
{
map<char, char> mmap;
for (int i = 0; i < s.size(); i++)
{
if (mmap.find(s[i]) == mmap.end())
{
mmap[s[i]] = t[i];
}
else
{
if (mmap[s[i]] != t[i])
{
return false;
}
}
}
return true;
}
};