Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isIsomorphic(string s, string t) {
- unordered_map<char,char> m;
- unordered_map<char,char> m2;
- bool ans=true;
- for(int i=0;i<s.length();i++)
- {
- if (m.find(s[i]) != m.end())
- {
- if(m[s[i]]!=t[i])
- {
- ans=false;
- break;
- }
- }
- else
- {
- m[s[i]]=t[i];
- }
- }
- for(int i=0;i<s.length();i++)
- {
- if (m2.find(t[i]) != m2.end())
- {
- if(m2[t[i]]!=s[i])
- {
- ans=false;
- break;
- }
- }
- else
- {
- m2[t[i]]=s[i];
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment