Leetcode 205. Isomorphic Strings
2018-01-01 14:41
435 查看
这题和Leetcode290. Word Pattern思路一样。
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char,char>m1, m2;
for(int i=0; i<s.size(); ++i)
{
if(m1.count(s[i]) && m1[s[i]]!=t[i] || m2.count(t[i]) && m2[t[i]]!=s[i] )
return false;
m1[s[i]]=t[i];
m2[t[i]]=s[i];
}
return true;
}
};
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char,char>m1, m2;
for(int i=0; i<s.size(); ++i)
{
if(m1.count(s[i]) && m1[s[i]]!=t[i] || m2.count(t[i]) && m2[t[i]]!=s[i] )
return false;
m1[s[i]]=t[i];
m2[t[i]]=s[i];
}
return true;
}
};
相关文章推荐
- [leetcode] 205. Isomorphic Strings
- LeetCode笔记:205. Isomorphic Strings
- 【Leetcode】205. Isomorphic Strings
- [leetcode]205. Isomorphic Strings
- [leetcode] 205. Isomorphic Strings
- leetcode 205. Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- leetcode 205. Isomorphic Strings 同构字符串判断 + HashMap
- 【LeetCode】205. Isomorphic Strings
- leetcode205. isomorphic strings
- 【LeetCode】205. Isomorphic Strings
- leetcode 205. Isomorphic Strings
- leetcode 205. Isomorphic Strings 巧妙使用hashmap.put返回值求解
- 【LeetCode】 205. Isomorphic Strings
- [LeetCode] 205. Isomorphic Strings
- [LeetCode] 205. Isomorphic Strings 解题思路 - Java
- LeetCode 205. Isomorphic Strings
- LeetCode205. Isomorphic Strings
- [leetcode]205. Isomorphic Strings
- Leetcode205. Isomorphic Strings