forked from harshitsuthar77731/algotoolkitmain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
205. Isomorphic Strings
42 lines (42 loc) · 928 Bytes
/
205. Isomorphic Strings
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
34
35
36
37
38
39
40
41
42
class Solution {
public:
bool isIsomorphic(string s, string t) {
map<char,char>m,m1;
for(int i=0;i<s.size();i++)
{
auto it = m.find(s[i]);
if(it==m.end())
{
m[s[i]]=t[i];
}
auto it2 = m1.find(t[i]);
if(it2==m1.end())
{
m1[t[i]]=s[i];
}
}
cout<<m1.size()<<" "<<m.size()<<endl;
if(m1.size()!=m.size())
{
return false;
}
for(int i=0;i<s.size();i++)
{
auto it = m.find(s[i]);
if(it==m.end())
{
m[s[i]]=t[i];
}
}
string temp = "";
for(int i=0;i<s.size();i++)
{
temp+=m[s[i]];
}
cout<<temp<<endl;
if(temp==t)
return true;
else
return false;
}
};