Leetcode # 205. Isomorphic Strings
- 2022.11.29
- LeetCode
https://leetcode.com/problems/isomorphic-strings/
Solution
Time Complexity: O(s.length())
Space Complexity: O(s.length())
class Solution {
public:
bool isIsomorphic(string s, string t) {
std::map<char, char> s2t, t2s;
for(int i = 0; i < s.length(); i++){
if(s2t.count(s[i])){
if(s2t[s[i]] != t[i])return false;
}else{
if(t2s.count(t[i]))return false;
s2t.insert({s[i], t[i]});
t2s.insert({t[i], s[i]});
}
}
return true;
}
};
Last Updated on 2023/08/16 by A1go