-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlt40.cpp
43 lines (39 loc) · 968 Bytes
/
lt40.cpp
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
43
class Solution {
public:
bool isIsomorphic(string s, string t) {
if(s.size()!=t.size()){
return false;
}
bool matching=true;
unordered_map<char,char> bind;
unordered_map<char,int> check;
int n=s.size();
for(int i=0 ; i<n ; i++){
if(bind[s[i]]!='\0'){
if(bind[s[i]]!=t[i]){
matching=false;
break;
}
else{
matching=true;
continue;
}
}
else{
if(check[t[i]]==1){
matching=false;
break;
}
matching=true;
bind[s[i]]=t[i];
check[t[i]]=1;
}
}
if(matching){
return true;
}
else{
return false;
}
}
};