class Solution { public: bool isMatched(const string s1, const string s2) { int len1 = s1.size(); int len2 = s2.size(); if (len1 == 0 && len2 == 0) return true; if (len1 != len2) return false; map<char, char> match; for (int i = 0; i < len1; i++) match[s1[i]] = '\0'; for (int i = 0; i < len1; i++) { if (match[s1[i]] == '\0') match[s1[i]] = s2[i]; else if (match[s1[i]] != s2[i]) return false; } return true; } void test() { cout << boolalpha << isMatched("loop", "feed") << endl; cout << boolalpha << isMatched("aba", "abb") << endl; } };
点赞 5

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务