-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathsolution.cpp
More file actions
33 lines (32 loc) · 754 Bytes
/
solution.cpp
File metadata and controls
33 lines (32 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution
{
public:
bool isIsomorphic(string s, string t)
{
map<char, char> m1;
map<char, char> m2;
bool flag = true;
for(int i=0; i<s.size(); ++i)
{
if(m1.find(s[i])==m1.end() && m2.find(t[i])==m2.end())
{
m1[s[i]] = t[i];
m2[t[i]] = s[i];
}
else if(m1.find(s[i])!=m1.end() && m2.find(t[i])!=m2.end())
{
if(m1[s[i]]!=t[i] || m2[t[i]]!=s[i])
{
flag = false;
break;
}
}
else
{
flag = false;
break;
}
}
return flag;
}
};