-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path205.cpp
More file actions
23 lines (21 loc) · 753 Bytes
/
Copy path205.cpp
File metadata and controls
23 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
bool isIsomorphic(string s, string t) {
if(s.size() != t.size())
return false;
unordered_map<char, char> myHash1;
unordered_map<char, char> myHash2;
for(int i = 0; i < s.size(); i++){
if(myHash1.find(s[i]) == myHash1.end() && myHash2.find(t[i]) == myHash2.end()){
myHash1[s[i]] = t[i];
myHash2[t[i]] = s[i];
}else{
if(myHash1.find(s[i]) != myHash1.end() && myHash1[s[i]] != t[i])
return false;
if(myHash2.find(t[i]) != myHash2.end() && myHash2[t[i]] != s[i])
return false;
}
}
return true;
}
};