class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param s string字符串
     * @param t string字符串
     * @return string字符串
     */
    string isIsomorphic(string s, string t) {
        // write code here
        int ls = s.size();
        int lt = t.size();
        if (ls != lt)return "NO";
        map<char, char>mp;
        map<char, char>::iterator it;
        char ch1, ch2;
        for (int i = 0; i < ls; ++i) {
            ch1 = s[i], ch2 = t[i];
            if (mp.find(ch1) != mp.end()) {
                if (mp[ch1] != ch2)return "NO";
            } else {
                for (it = mp.begin(); it != mp.end(); it++) {
                    if (it->second == ch2)return "NO";
                }
                mp[ch1] = ch2;
            }
        }
        return "YES";
    }
};

一、题目考察的知识点

map,看到了对应应该要想到map迭代器的

二、题目解答方法的文字分析

首先判断,如果字符串长度不同那肯定是不行的

然后遍历,遍历的过程中,检查字符是否在哈希表中,如果存在冲突那肯定是不行的

如果遍历完没有冲突那就是可以的

三、本题解析所用的编程语言

c++