题目考察的知识点:字符串
题目解答方法的文字分析:用map一个字符对应一个字符,判断是否相同;用s映射t,再用t映射s,都true,即返回yes。
本题解析所用的编程语言:c++
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return string字符串 */ bool _isIsomorphic(string& s, string& t) { if (s.size() != t.size()) return "false"; map<char, char> map; for (int i = 0; i < s.size(); ++i) { auto it = map.find(s[i]); if (it == map.end()) map.insert(pair(s[i], t[i])); else if (it->second != t[i]) return false; } return true; } string isIsomorphic(string s, string t) { // write code here if (_isIsomorphic(s, t) && _isIsomorphic(t, s)) return "YES"; return "NO"; } };